The program that you write should be clear not only to you, but also to the reader of
your program. Part of good programming is the inclusion of comments in the program.
Typically, comments can be used to identify the authors of the program, give the date
when the program is written or modified, give a brief explanation of the program, and
explain the meaning of key statements in a program. In the programming examples, for
the programs that we write, we will not include the date when the program is written,
consistent with the standard convention for writing such books
There are two common types of comments in a C++ program—single-line comments
and multiple-line comments.
- Single-line comments begin with // and can be placed anywhere in the line. Everything
encountered in that line after // is ignored by the compiler. For example, consider the
// This is a C++ program. It prints the sentence:
// Welcome to C++ Programming.
- Multiple-line comments are enclosed between /* and */. The compiler ignores anything
that appears between /* and */. For example, the following is an example of a multiple-line
You can include comments that can
occupy several lines.