C++ Comments


A comment helps improve the readability and understanding of the program.

Comments are fully disregarded by C++ compilers.

There are two types of comments in C++ programming language:

  • Single-line comment
  • Multi-line comment

Single-line Comments

Single-line comments start with two forward slashes (//).

Any text between // and the end of the line is ignored by the compiler (will not be executed).

Syntax

// This is a single line comment

Example

#include 
 
int main(void) {
    // This is a single-line comment
    printf("Welcome to Tamalolearn");
    return 0;
}

Output

Welcome to Tamalolearn

Multi-line Comments

Multi-line comments start with /* and ends with */.

Syntax

/*Comment starts
    continues
    continues
    .
    .
    .
Comment ends*/

Example

#include

int main(void) {
    /*
    This is a
    multi-line comment
    */
   
      /*
    This comment contains some code which
    will not be executed.
    printf("Code enclosed in Comment");
    */
    printf("Welcome to GeeksforGeeks");
    return 0;
}

Output

Welcome to GeeksforGeeks