Home >>C++ Tutorial >C++ Comments

C++ Comments

Comments in C++

The statements that are not executed by the compiler are known as the C++ comments. In order to provide the explanation of the variable, method, code or class, the comments in the C++ programming is used. The user can hide the program with the help of C++ comments.

There are generally two types of comments in the C++ programming:

  • Single line comments
  • Multi-line comments

1. Single line comments in C++

The single line comment generally starts with double forward slashes. Here is an example of the single line comment in C++:

#include <iostream>  
using namespace std;  
int main()  
{  
 int a = 10; // Here a  is a variable      
 cout<<a<<"\n";         
}
Output : 20.

2. Multi-line Comment in C

Comments that are used to comment multiple lines of code are known as the Multi-line Comments. This comment is denoted by the forward slash and asterisk (/*……*/).

Here is an example of the multiple line comments that will help you in understanding the concept:

#include <ostream>  
using namespace std;  
int main()  
{  
/*Define a variable  and   
print the  variable in C++. */   
 int a = 20;     
 cout<<x<<"\n";         
}
Output : 20.

No Sidebar ads