Comments in C++

In a programming language, comments are either used for explaining code or to prevent execution of code while testing alternate code.

There are two types of comments in C++:

  • Single-line Comments
  • Multi-line Comments

Single-line Comments

Single-line comments are done by starting the comment with double forward slash //

Example

// This is a comment example
cout << "Hello comment!";

Anything which is after // on the same line will be ignored by the c++ compiler.

Multi-line Comments

Multi-line comments are done by starting the comment with /* and ending with */

Example

    /* This is a multi line comment example
       This will be ignored by the compiler */
    cout << "Hello comment!"; 

Anything which is between /* */ will be ignored by the C++ compiler.