C++ Comments
Comments are used to describe the code. These lines are not displayed in the website. It offers an option of leaving notes for yourself or others. The comment simplifies the production of more readable code. Like C there are two types of comments in C++:
- Single-line Comment
- Multi-line Comment
Single-line Comment
A single-line comment is represented by //. It is used for commenting a single line.
Example
#include <iostream>
using namespace std;
int main()
{
// This is a single line comment
cout << "Hello, World!";
return 0;
}
Output:
Hello, World!
Multi-line Comment
Multi-line comments open with /* and close with */.
Example
#include <iostream>
using namespace std;
int main()
{
/* This is a
multi-line comment */cout << "Hello, World!";
return 0;
}
Output:
Hello, World!