C++ Comments

C++ supports the C comment format where /* begins a comment and */ ends it. But C++ has another comment format which is preferred by many programmers. The C++ comment token is the double-slash (//) sequence. Wherever this sequence appears (unless it is inside a string), everything to the end of the current line is a comment.

The next example adds comments to the previous program.

// C++ comments

#include <iostream.h>

void main()

{

char name[20]; // Declare a string

cout << "Enter a name...\n"; // Request a name

cin >> name; // Read the name

cout << "The name you entered was " << name;

}