C plus plus Comments

Comments in C plus plus are statements that are not executed by the compiler. The comments in C++ programming can be used to provide explanation of the code, variable, method or class. By the help of comments, you can hide the program code also.

There are two types of comments in C++.

  1. Single Line comment
  2. Multi Line comment

C++ Single Line Comment

The single line comment starts with // (double slash). Let’s see an example of single line comment in C++.

 
  • #include <iostream>  
  • using namespace std;  
  • int main()  
  • {  
  •  int x = 11; // x is a variable      
  •  cout<<x<<“\n”;         
  • }  

Output:

11

 

C++ Multi Line Comment

The C++ multi line comment is used to comment multiple lines of code. It is surrounded by slash and asterisk (/∗ ….. ∗/). Let’s see an example of multi line comment in C++.

 
  • #include <ostream>  
  • using namespace std;  
  • int main()  
  • {  
  • /* declare and   
  • print variable in C++. */   
  •  int x = 35;     
  •  cout<<x<<“\n”;         
  •  

Output:

35

 

Leave a Reply