how to Write first program in C++
Writing first C++ Program Part 2
Using cout endl (/n) and comment (//) in C++
What is cout?
It is use to display something on the screen in C++.
Syntax
cout<<”something to be print”;
Example
#include<iostream.h>
int main()
{
cout<<”Hollow world”;
system (“pause”);
return 0;
};
What is endl or (/n)?
It is use to start new line in C++ program.
Syntax
cout<<”hello world”<<’/n’;
Or
cout<<”hello world”<<endl;
Example
#include<iostream.h>
int main()
{
cout<<”Hollow world”<<’/n’;
cout<<”My Best friend is Waqas Ahmad<<endl;
system (“pause”);
return 0;
};
What is comment (//)?
It is use to make a line or a group of line useless in C++. When we use the comment than that line will not execute. Syntax // writing something here // this is my comment Example
#include<iostream.h>
int main()
{
//print my name
cout<<”Haroon Muhammad”<<’/n’;
system (“pause”);
return 0;
};
Similar if we want to comment the whole paragraph in C++ so we use slash with star to start the comment and use star with slash to end the comment .
Syntax
/* I am commented
I am comment
*/
Example
#include<iostream.h>
int main()
{
cout<<”Hollow world”<<’/n’;
/* cout<<”My Best friend is Waqas Ahmad<<endl;
cout<<”Our Cr Atta ullah is genital man”;
*/
system (“pause”);
return 0;
};
Blank space and empty line in C++? Blank space or empty line in C++ does not affect your program and compiler does not read this blank space or line.