C++-Comment .

In this session i have discussed comment in C++ .


The comment is used to provide the information to reader of program . The compiler ignore the comments . There are two types of comment in C++ as follows .

1-Single line comment

2-Multiline comment


1-Single line comment

The single line comment is used to provide the information in a line . It is represented by doblue slash (//) .

In the below program comment is This program add the two numbers .

Example : Write a program that add two numbers with comment .

    #includ<iostream.h>
    using namespace std; 
    int main()
    {  
          //This program add the two numbers
          int x,y,sum=0;
          cout<<"Enter the first number : ";
          cin>>x;
          cout<<"Enter the second number";
          cin>>y;
          sum=x+y;
          cout<<"Sum : "<<sum;
          return 0;
    }
    
    OUTPUT : Enter the first number : 10
             Enter the second number : 20
             Sum : 30
    

2-Mulitline comment

The multiline comment is used to provide the information in more than one line . It is represented by the slash with asterisk like this /* */ .

Example : Write a program that add two numbers with comment .

    #includ<stdio.h> 
    int main()
    {  
          /*This program add the two numbers
            the program use two varibale x
            and y to sum and assign in sum
            variable */       
          int x,y,sum=0;
          cout<<"Enter the first number : ";
          cin>>x;
          cout<<"Enter the second number";
          cin>>y;
          sum=x+y;
          cout<<"Sum : "<<sum;
          return 0;
    }
    
    OUTPUT : Enter the first number : 10
             Enter the second number : 20
             Sum : 30
    

Welcome to AndroidATPoint.

back image                     next image