C++ Comments
Program comments are explanatory statements. You can include comments in your C++ code, which improves the readability of the source code. All programming languages allow some form of comments.
C++ supports single-line comments and multi-line comments. All characters in comments are ignored by the C++ compiler.
C++ comments generally have two types:
-
//- Usually used for single-line comments.
-
/* ... */- Usually used for multi-line comments.
Comments start with//It starts at and continues until the end of the line. For example:
Example
It can also be placed after a statement:
Example
When the above code is compiled, the compiler will ignore// This is a commentand// Output Hello World!, and finally the following result will be produced:
Hello World!
C++ comments end with/*starts with*/termination. For example:
In/*and*/Inside a comment,//The character has no special meaning. In//Within a comment,/*and*/the characters, as they have no special meaning. Therefore, you can nest one type of comment within another. For example: