C++ Programming/Code/Style Conventions/Comments

Comments
Comments are portions of the code ignored by the compiler which allow the user to make simple notes in the relevant areas of the source code. Comments come either in block form or as single lines.
 * Single-line comments (informally, C++ style), start with  and continue until the end of the line. If the last character in a comment line is a   the comment will continue in the next line.
 * Multi-line comments (informally, C style), start with   and end with.

We will now describe how a comment can be added to the source code, but not where, how, and when to comment; we will get into that later.

C style comments
If you use C style comments, try to use it like this:

Comment single line:

Comment multiple lines:

This allows you to easily uncomment. For example:

Uncomment single line:

Uncomment multiple lines:

... by removing only the start of comment and so activating the next one, you did re-activate the commented code, because if you start a comment this way it will be valid until it finds the close of comment.

C++ style comments
Examples:

or

The backslash is a continuation character and will continue the comment to the following line:

Comments are also sometimes used to enclose code that we temporarily want the compiler to ignore. This can be useful in finding errors in the program. If a program does not give the desired result, it might be possible to track which particular statement contains the error by commenting out code.
 * Using comments to temporarily ignore code


 * Example with C style comments

or

Combining multi-line comments with c++ comments  to comment out multiple lines of code:
 * C and C++ style

Commenting out the code:

uncommenting the code chunk

This works because a  is still a c++ comment. And  acts as a c++ comment and a multi-line comment terminator. However this doesn't work if there are any multi-line comments are used for function descriptions.

Another way (considered bad practice) is to selectively enable disable sections of code:
 * Note on doing it with preprocessor statements

this is considered a bad practice because the code often becomes illegible when several #if's are mixed, if you use them don't forget to add a comment at the #endif saying what #if it correspond

you can prevent illegibility by using functions (often considered better than macros for legibility with no performance cost) containing only 2 sections in #if #else #endif

and call

in the program