Comments in C language

Comments in C language

Comments in c language are add-in code because of making the code easier to understand. It makes the code more readable and hence easy to update the code later. Comments are ignored by the compiler while running the code. It is a simple text that makes your code more descriptive and readable. Comments are not a necessary part of a code, you can add them according to your convenience.

There are two types of comments in c.

    • Single line comment

    • Multi-Line Comments

1. Single Line Comment

Single line comment starts with // and ends with the end of that line. Anything after // to the end of the line is a single-line comment and will be ignored by the compiler. For single-line comments just put ‘//’ before the comment line.

Syntax

//single line comment.
statements; //single line comment.

Program for single-line comment in C language

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

Output

Hello C

2. Multi-Line Comments in c language

Multi-Line comment starts with /* and ends with */. Between /* and */ is a block comment and will be ignored by the compiler.

It is represented by a slash asterisk \* … *\ this comment can occupy many lines of code, but it can’t be nested.

Syntax

/*  
code 
to be commented 
*/  

Program for multi-line comment in C

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

Output

Hello

 

 

Also read, Tokens in C

Share this post

Leave a Reply

Your email address will not be published. Required fields are marked *