Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- OK!
- In C++
- We use
- //
- for one line comments
- examples:
- //this is a comment
- or
- int a=5; //a one line comment can come here too without any problems ;)
- and /* */
- for more lines
- example:
- /* this is a big comment */
- or /* this
- is
- a
- big
- comment */
- or int a /* OK! The int variable name here is a ;) */ =5; //I know this example is looking ugly but still it's just an example ;)
- cout outputs a message to the screen
- cin takes in user input
- int=integer; //Example: int x = 999;
- float=float; //Example: float y = 5.7;
- bool=true /* or */ false; //That is exactly like this: bool a=true; bool b=false;
- double=double; //Example: double z = 998894.54982;
- Double means "Double precision Floating-point number" while Float means "Floating-point number"
- float vs double : double wins because double can take more numbers. For simple numbers like 599.75 always use float but for complicated numbers like 998894.54982 always use double. Why? Because when doing maths in C/C++ using double is like a must because double is more precise than float! Float can round numbers too when the answer is longer than it's storing capacity but usually numbers are not too bigger than double's storing capacity hence always using double when doing maths in C/C++ is better ;)
- char is "character" & char is for 1 letter
- char a="h";
- varchar is "variable characters" & varchar is for up to 4000 letters at once ;)
- varchar vc = "Hello World or Hello world or hello World or hello world"
- bool is for true or false
- bool a=true; //never use bool a="true"; always use bool a=true; because C/C++ does know what is true with bool data type
- bool b=false; //never use bool b="false"; always use bool b=false; because C/C++ does know what is false with bool data type
- using of const
- we can not change value of a constant (that is const)
- for example:
- const int a=4;
- a=3;
- this is wrong! Because we can not change the value of a constant after it's declared :(
- another example:
- int a=4;
- a=3;
- this is correct! Because we can always change the value of a variable anytime we want ;)
- with sizeof()
- we take the memory size of a variable
- for example:
- int a=5;
- cout<<sizeof(int);
- this will print
- 4
- because int=4 in your computer's memory (or might be different :P)
- it is about your computer!
- cout<<sizeof(a);
- is the same as
- cout<<sizeof(int);
- because a is declared as an int!
- So, the result will be
- 4
- again! Because /*remember*/ a is decalred as an int ;)
- #include <iostream>
- using namespace std;
- int main(int argc, char ** argv) {
- int a=5;
- cout<<sizeof(5);
- }
- this will print
- 4
- not 5
- because 5 is an int
- and int=4 in your computer (or might be different :P)
- -------
- lets go in "if else" statements now
- we declare it as
- if(expression) {
- statement1
- } else {
- statement2
- }
- example:
- int a=5;
- if(a==5){
- cout<<"a is 5";
- } else {
- cout<<"a is not 5"
- }
- also, if we want to check more things
- we use "else if"
- example:
- #include <iostream>
- using namespace std;
- int main(int argc, char ** argv) {
- int a;
- cin>>a;
- if(a>5) {
- cout<<"a is greater than 5";
- } else if(a<5) {
- cout<<"a is smaller than 5";
- } else {
- cout<<"5";
- }
- }
- Lecture Ends Here ;)
- -------
- Challenges Start Here ;)
- So,
- Challenge is:
- Make a program
- that declares all variables int, float & most other types
- and after putting them
- example:
- int a;
- cin>>a;
- cout<<a;
- float b;
- cin>>b;
- cout<<b;
- etc....
- continue the program (in whatever way you want) & then use everything in the program (take the example above for an example)!
- int, bool, char, varchar etc...
- --"Owl" & "XRahat2011" Participated In Challenge & Both Succeeded Without Any Mistakes ;)
- Challenges Finish Here ;)
- -------
- HomeWork Starts Here ;)
- Make a very simple calculator that can add, subtract, divide & multiply numbers ;)
- HomeWork Ends Here ;)
- -------
- ** The End ;)
- ** Class Moderated By "XRahat2011" ;)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement