C++ Comments

C++ Comments


C++ Comments

The C++ comments are statements that are not executed by the compiler.A comment is an annotation in a source code with the intention to give a programmer a readable explanation of the code.  The comments in C++ programming can be used to provide explanation of the code, variable, method or class. By the help of comments, you can hide the program code also.

There are two types of comments in C++.

  • Single line Comment
  • Multi line Comment

Single line Comment:

Single line comment denoted by // (two forward slashes). A new line not immediately preceded by a backslash terminates this form of comment. Therefore, it is commonly called a "single-line comment" as shown below.

Example :

Output :

Multi Line Comment:

Multi line comment denoted in between by /*(forward slash and asterisk) marks the beginning of the comment, and the */( asterisk and forward slash) marks the end. You can have your comment span multiple lines and anything between those /*…*/ is considered a comment for example as shown below.

Output :