Comments In Cpp
Comments:
Comments are parts of the source code disregarded by the compiler. They simply do nothing. Their purpose is only to allow the programmer to insert notes or descriptions embedded within the source code.
C++ supports two ways to insert comments:
Syntax
// line comment
/* block comment */
The first of them, known as line comment, discards everything from where the pair of slash signs (//) is found up to the end of that same line. The second one, known as block comment, discards everything between the /* characters and the first appearance of the */ characters, with the possibility of including more than one line.
We are going to add comments to our second program:
CODE/PROGRAM/EXAMPLE
/* my second program in C++ with more comments */
#include <iostream>
using namespace std;
int main ()
{
cout << "Hello World! "; // prints Hello
World!
cout << "I`m a C++ program"; // prints I`m a
C++ program
return 0;
}
CODE/PROGRAM/EXAMPLE
O/P : Hello World! I'm a C++ program
If you include comments within the source code of your programs without using the comment characters combinations //, /* or */, the compiler will take them as if they were C++ expressions, most likely causing one or several error messages when you compile it.