C++ Comments

Comments are used to explain C++ code and make it more readable. Comments are ignored by the compiler. C++ supports:

  • Single-line comments — start with //
  • Multi-line comments — start with /* and end with */

Example

#include <iostream>
  using namespace std;
  
  int main() {
      // This is a single-line comment
      cout << "Hello!" << endl;
  
      /*
        This is a multi-line comment.
        It spans multiple lines.
      */
      cout << "This is C++." << endl;
  
      return 0;
  }

Output

Hello!
  This is C++.

Explanation

  • // is used for single-line comments.
  • /* ... */ is used to write multi-line comments.
  • Comments do not affect the actual output.