Comments in C and C++

Comments are used for the purpose of internal documentation. They are replaced during preprocessing by a single space character so they do not affect the compilation of the program. Comments can span more than one line, and can be put anywhere the language allows white space. Multibyte characters can also be included within a comment.

You cannot nest comments.

Syntax

// comment goes here

Example:

void main ()
{ 
     // This is a comment in a C++ program
} 

The comment begins after the double slash. Any text that occurs after the double slash (to the end of the line) is considered as part of the comment. Therefore, comments should be placed at the end of program statements or on a line of its own.

If the lang(slashslashcomments, ...) compiler option is in effect when you compile a C program, double slash (//) also specify the beginning of a comment.

This is the default for VisualAge C++. C++ permits double-slash comments as part of the language definition.

A C++ comment can span more than one physical source line if it is joined into one logical source line with the line-continuation (\) characters. The backslash character can also be represented by a trigraph.

Syntax

/* comment goes here */

Example:

int main (void)
{ 
     /* This is a comment in a C program */
     return 0;
}