Follow The New Tutorial updates on WhatsApp, Telegram or YouTube.

Comments in C Language

Comments in C language are used to provide information about lines of code. Comments are not executed as part of the program. It is widely used for documenting code.

Generally Comments are used to provide the description about the logic written in program.

Comments are not display on output screen.

A well-documented program is a good practice as a programmer. Comments help the developer understand the logic/algorithm of the code if he revisits it after a long time.

Types of comments

There are 2 types of comments in the C language.

  1. Single Line Comments
  2. Multi-Line Comments

Single Line Comments

Single line comments are represented by double slash \\. It is used to denote a single line comment. It applies comment to a single line only.

Syntax

//Your comment here

Example

#include<stdio.h>    
int main(){    
    //printing information - This is comment   
    printf("Hello C");  
printf("\nEven you can place the comment after the statement.");//printing information - This is comment.
return 0;  
}      

Multi Line Comments

Multi-Line comments are represented by slash asterisk \* … *\. It can apply comment to more than a single line.

It can occupy many lines of code, but it can’t be nested.

Syntax

/*  
code 
to be commented 
*/ 

Example

#include<stdio.h>    
int main(){    
    /*printing information   
      Multi-Line Comment*/  
    printf("Hello C");    
return 0;  
}