Professional Documents
Culture Documents
• endl manipulator
• Escape sequences
• Comments
• Types of comments
• Single-Line comment
• Multi-Line comment
• Comments example
2
endl Manipulator
• The endl is one of the manipulator which changes the format of cout
statement.
• It brings the text on new line.
• It is used with in cout statement.
• The name endl is included in std namespace.
3
endl Manipulator
#include<iostream>
#include<conio.h>
int main()
{
cout<<"14 Computer Systems"<<endl;
cout<<"MUET"<<endl;
cout<<"Jamshoro";
getch();
return 0;
}
4
endl Manipulator
Output on monitor screen
5
endl Manipulator
Same program can also be written as
#include<iostream>
#include<conio.h>
int main()
{
cout<<"14 Computer Systems"<<endl<<"MUET"<<endl<<"Jamshoro";
getch();
return 0;
}
6
endl Manipulator
Same program can also be written as
#include<iostream>
#include<conio.h>
int main()
{
std::cout<<"14 Computer Systems"<<std::endl;
std::cout<<"MUET"<<std::endl;
std::cout<<"Jamshoro";
getch();
return 0;
}
7
Escape Sequence
8
Escape Sequence
9
Escape Sequence
Escape Sequence Description
10
Escape Sequence ( \n )
#include<iostream>
#include<conio.h>
int main()
{
cout<<"14 Computer Systems\nMUET\nJamshoro";
getch();
return 0;
}
11
Escape Sequence ( \n )
Same program can also be written as
#include<iostream>
#include<conio.h>
int main()
{
cout<<"14 Computer Systems\n";
cout<<"MUET\n";
cout<<"Jamshoro";
getch();
return 0;
}
12
Escape Sequence ( \n )
13
Escape Sequence ( \t )
#include<iostream>
#include<conio.h>
int main()
{
cout<<"14 Computer Systems\tMUET\tJamshoro";
getch();
return 0;
}
14
Escape Sequence ( \t )
15
Escape Sequence ( \’ ) ( \” ) ( \\ )
#include<iostream>
#include<conio.h>
int main()
{
cout<<"\"14 Computer Systems\" \n";
cout<<"\'MUET\'\t \\Jamshoro";
getch();
return 0;
}
16
Escape Sequence ( \’ ) ( \” ) ( \\ )
17
Escape Sequence
18
Comments
• Comment is the text that is used to explain the code inside the program.
• A comment is a line (or multiple lines) of text that are inserted into the source code
to explain what the code is doing.
• The programmer writes the comments in the program to make is easier to read for
other persons (who want to read it).
• The comments are always ignored (not executed) by the compiler.
• The comments are non-executable statements in the program.
• Compiler does not consider comments as part of the program.
• Comments are also helpful during debugging the program.
19
Types of Comments
20
Single-Line Comment
For Example:
getch(); //gets single character from the keyboard
21
Multi-Line Comment
• Multi-Line comment, comments out multiple lines of the code.
• It starts with slash asterisk /* .
• It ends with asterisk slash */.
• Any text written in between /* and */ is ignored by the compiler and is
considered as the comment.
For Example:
/*This program displays string on screen
It is written by Sir Ali
It is a basic C++ program */
22
Comments Example
/*This program displays string on screen
It is written by Sir Ali
All the text in GRAY
It is a basic C++ program */ color is comment