Comments in C++?


Comments in C++

  • Comments are portions of the code ignored by the compiler which allow the user to make simple notes in the relevant areas of the source code. Comments come either in block form or as single lines. Single-line comments (informally, C++ style), start with // and continue until the end of the line.


  • Program comments are explanatory statements that you can include in the C++ code.
  • These comments help anyone reading the source code.
  • All programming languages allow for some form of comments.
  • C++ supports single-line comment.
  • and multi-line comments.
  • All characters available inside any comment are ignored by C++ compiler.

C++ comments start with /* and end with */.

For example −

single line comment 

/* This is a comment */ double line comment or multi-line comments.
/* C++ comments can also * span multiple lines */

A comment can also start with //, extending to the end of the line. For example 

#include <iostream>

using namespace std;

main() {

cout << "Hello World"; // prints Hello World

return 0;


When the above code is compiled, it will ignore // prints Hello World and final executable will produce the following result −

Hello World


Related Topics