Saturday 1 December 2018

Commets in C++ program

Comments and their syntax in C++

Each C++ statement is terminated by a symbol named semicolon(;) which is called statement terminator.In C++, the separation between statement is specified with this ending semicolon (;) at the end of each statement. It does not matter to write more  than one statement on a single line but matter if you do not separate them with  semicolons. The use of each statement on a separate line is only to add clarity in 
the program.

Single line comment
It is represented by the double slash symbol //.It discards everything from where
The pair of slashes signs // is found up to the end of the same line.

Multiline comment

These types of comments are represented by the symbol /*...............*/. It ignores 
everything between the /* characters and the first appearance of the */ characters
, with the possibility of including more than one line.

Consider the following program to demonstrate comments.

/* program to demonstrate comments in C++ */
#include <iostream.h>
#include <conio.h>
int main()
{
cout<<”Welcome!;    //prints Welcome!
cout<< “I’m a C++ program demonstrating comments”;
getch ();
return 0;
}

Output of the program
Welcome!
I’m a C++ program

In the above example,the first lines are multi-line comments while the comment at
line  6 is a single line comment.

0 comments: