Website For Developers

Comments in C++




Single line comment

In single line comments we just tell about a single line. We can do it with the operator "//"

Example of single line

#include<iostream>
using namespace std;
int main() {
  // this is a single line comment
  return 0;
}


Multi lines comment

We can do it with putting "/*" operator at the start and "/*" operator at the end.
This syntax can also be used for single line commenting.

Example of multi lines

#include<iostream>
using namespace std;
int main() {
  /* This is also single line comment.*/
/* This is
multiple
Line comment.*/

  return 0;
}


Advantages of comments in C++

- Comments in c++ are used for user documentation purpose.
- It also used for hide the non-usable code.
- Comments in c++ are also used to explain particular statement.
- xMoreover, if your program is not running properly and you are not getting what you want instead of removing the code just put few lines as a comment which you think should not be there.