C++ Comments

The C++ comments are used to insert notes into the source code and are meant only to enhance the readability of the code. The C++ comments are statements that are not executed by the compiler. .

There are two types of comments in C++.

  • Single Line comment
  • Multi Line comment

Single Line Comment

The single line comment starts with // (double slash) and causes the compiler to ignore everything that follows the slashes on the same line. Let's see an example of single line comment in C++.

Example
snippet
#include <iostream>
using namespace std;
int main()
{
 int x = 11; // x is a variable    
 cout<<x<<"\n";       
}
Output
11

Multi Line Comment

The C++ multi line comment is used to comment multiple lines of code. It is surrounded by slash and asterisk (/∗ ..... ∗/). Everything within the opening /∗ and the closing ∗/ is a comment, even if it stretches over multiple lines. Let's see an example of multi line comment in C++.

Example
snippet
#include <ostream>
using namespace std;
int main()
{
/* declare and  
print variable in C++. */ 
 int x = 35;   
 cout<<x<<"\n";       
}
Output
35
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents +