Comments line in C++

Comments are explanatory statements that you can include in C++ code to explain what the code is doing. The compiler ignores everything that appears in the comment,so none of that information shows in the result.

Single-Line Comments:
Comments that require lines begin with //. You can place them on the single line

For example:

#include<iostream.h>
using namespace std;
int main()
{
     //prints "Hello world"
     cout<<"Hello world";
     return 0;
}

Output:

Hello world

Multi-Line Comment:
Comments that require lines begin with /* and end with */.
You can place them on the same line or insert one or more lines between them.
For example:

#include<iostream.h>
using namespace std;
int main()
{
     /*This is a comment.
     prints "Hello world" */
     cout<<"Hello world";
     return 0;
}

Output:

Hello world

Note:-
Comments can be written anywhere, and can be repeated any number of times throughout the code.


You've successfully subscribed to Developer Insider
Great! Next, complete checkout for full access to Developer Insider
Welcome back! You've successfully signed in
Success! Your account is fully activated, you now have access to all content.