Comments in C++

In this section of C++ tutorial, we will have a look at how to comment in the C++ programming language.

Comments are pieces of the code neglected by the compiler which support the user to make simple notes in the relevant areas of the source code. Comments come either in block form or as single lines.

Types of Comments in C++

Single-line comments

In C++ programming language it starts with // and it’s impact 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.

Example:

//I am single line comment

Multi-line comments

In C++ programming language it starts with /* and end with */.

Example:

/*I am a
Multi-line 
comment*/

It should be avoided to use one-line C-style comments since they are considered obsolete. Comments in the single-line style C and C++ are viewed as poor practice. One exception, which is common, is to deactivate a certain part of the code for test/debug purposes in the middle of a single line statement, any such action in the release code should be removed.

Leave a Comment

Your email address will not be published. Required fields are marked *