Post on 12-Apr-2017
transcript
Output in c++
Output is the things that appears on the console screen
What do you think we do in order to print something on the screen?
cout << ;
A key word that hastto be used in stuff on the screen This is called a semicolon
and is used to indicate the end of the statement
In this space between (cout) and (;) we write the thing that we want to print
Let’s try these codes:
cout << 3; cout << 3+4;
cout << 3*4; cout << 4/2;
cout << 4-3;
Note: I can print more than one thing with 1 coutcout << 3 << 6 << 2; Result : 362
If we want to print a word or a sentence we have to put it inside “ “ (double quotes).
cout << “Ghada;”
cout << “Hello World;”!
If I want to print a single character we have to put it inside ’ ‘ (single quotes).
cout << ‘a; ’ cout << ‘A;’
We know that if I said : cout << “Hello” <<“world ; ”The result printed on screen will be :Helloworld;
What if I want to make it (Hello world) with a space between the 2 words??
Answer:
cout << “Hello” << “ “ << “world; ”
Anything in a “” will be printed as it is, so when I put a space between “” it will be printed as a single spacebetween the 2 words
cout << “Hello” << “_” << “world;” Result : Hello_world
cout << “….” << “Hello” << “….” << “world;”.…“ << ” Result : …Hello…world…
cout << 3 + 4; cout << “3 + 4”;Result: Result:7 3 + 4
The operation is put inside ”“ so it is not treated as an operation,it is treated as a sentence which needs to be printed as it is.
A normal operation.So the value is calculatedand printed on the screen.
cout << “This is the first line;”cout << “This is the second line;”
Try these 2 lines of code and see what the output will look like.Result: This is the first lineThis is the second line
What if we want to print each statement in a separate line??cout << “This is the first line” << endl;
cout << “This is the second line;”Result: This is the first line
This is the second line
Prints a new line after printing the first statement