Skip to content

Latest commit

 

History

History
59 lines (46 loc) · 1.42 KB

Comments-in-Cpp.md

File metadata and controls

59 lines (46 loc) · 1.42 KB

Comments in C++

Comments are statements generally which are not executed by the compiler. It is written for the user to understand the purpose of the program or the source code written by the programmers. Also written to provide information about the variables, methods, class.

There are 2 types of comments in C++:

  • Single Line Comments
  • Multi Line Comments

Source: GeeksForGeeks

Single Line Comment

A single line comment starts with "//" i.e., a double slash.

Example Program

#include <iostream>
using namespace std;
int main()
{
    int j; //j is declared.
    cin>>j; // reads input for j from user.
    cout<<j; //displays the value of j
}

Output:

5
5

Multi Line Comment

A multi line comment is used in C++ when there are many lines of code or a huge explaination or a huge question of a program. It starts and ends like "/*....*/" i.e., a slash and a asterisk.

Example Program

/* This program is used to demonstrate the use of multi line comment.*/
#include <iostream>
using namespace std;
int main()
{
    int j;
    cin>>j; 
    cout<<j; 
    /* j is declared, then input of j is read and then it's value is displayed.*/
}

Output:

10
10