Comment types in C++

Comment types in C++

June 30, 2024·İbrahim Korucuoğlu
İbrahim Korucuoğlu

We are demontrating single line and multi line comments in C++

#include <iostream>
using namespace std;
// we will demonstrate the use of comments  in this program
int main() {
    // This is a single line comment
    cout << "Hello, World!" << endl; // This is also a single line comment
    /* This is a multi-line comment
    This is a multi-line comment
    This is a multi-line comment
    */
    return 0;
}

In the above code, we have used single-line comments and multi-line comments.

Single-line comments start with // and end at the end of the line.

Multi-line comments start with /* and end with */.
Comments are ignored by the compiler and are used to make the code more readable and understandable.
Output:
Hello, World!
In the above code, we have used comments to explain the code. You can also use comments to disable a part of the code.

Last updated on