c++ comments
c++ introduces a new comment symbols//(double slash)
The comments start with a double forward slash symbol and terminate at the end of the line.
A comment may start anywhere in the line of the program, and whatever follows till the end of the line is ignored.
Note
that there is no closing symbol of the double slash comment(//) or single line comments the double slash(//) comment is basically as single line comment.
and The Multiline comments can be written as follows
Now lets take example of comments to understand
// variable A to represent Average salary (Single line comment)
/* variable A to represent Average salary and this is program
for find average salary */ (multi line comment)
|
Given below are 3 important points regarding comments:
1. The space should not be between the // (forward slashes) Take the examples
/ / is incorrect. because there is space between forward slashes
as same, there should not be any space between the slash and star characters in
/* and */ correct
/* and * / incorrect.
|
2. Comments do not nest, Example /* programming */ comment has no special meaning inside /* */
Similarly, // comment has no special meaning inside
3. should not write comments inside character literals (such as characters enclosed between single quotes).
Comments inside String literals (such as, the text enclosed between double-quotes) are behave as part of the String’s content.
The another multiline comments are also symbols
are still valid and are some suitable for multiline comments
the following comment is allowed
The comments may be single line or multiple line. we can write comments anywhere in the program for example double slash comments cannot be used int the manner as shown below
for(i=0; i < n; i++)
examples of single line comment
The example of single line comment
int main()
{
// printing string
cout<<"This is c++ program";
return 0;
}
|
The example of Multi line comment
main()
{
/* printing string this is multi line
comment */
cout<<"This is c++ program";
0;
} |