Thursday, October 3, 2019

Using comments in c

Comments in C language are used to provide information about lines of code. It is widely used for
documenting code. 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 \\. Let's see an example of a single line comment in C.
  1. #include<stdio.h>    
  2. int main(){    
  3.     //printing information    
  4.     printf("Hello C");    
  5. return 0;  
  6. }      

Output:

Hello C
Even you can place the comment after the statement. For example:
  1. printf("Hello C");//printing information  

Multi Line Comments

Multi-Line comments are represented by slash asterisk \* ... *\. It can occupy many lines of code, but it can't be nested. Syntax:
  1. /*  
  2. code 
  3. to be commented 
  4. */  
Let's see an example of a multi-Line comment in C.
  1. #include<stdio.h>    
  2. int main(){    
  3.     /*printing information   
  4.       Multi-Line Comment*/  
  5.     printf("Hello C");    
  6. return 0;  
  7. }       

Output:

Hello C

No comments:

Post a Comment