Comments makes a program more readable and provide clarity to the C code. Comments are widely used for documenting C code.
In C programming language a comments are statements which are not executed by the compiler. A comments can include any combination of characters and a comments can appear anywhere and it allows white-space character.
There are two types of comments. They are,
- Single line comment
- Multi-line comment
Single line comment
Single line comment is used to comment a single line of code. A single line comment starts with double slash(//).
Example:
#include<stdio.h>
int main()
{
//This is an example for single line comment
printf("Welcome To C Tutorial"); //This is an printing statement
return 0; //This is an returning statement
}
Output:
Welcome To C Tutorial
Multi-line comment
Multi-Line comments are used to comment more than one-line of code. Multi-Line comments starts with forward slash and asterisk (/*) and ends with asterisk and forward slash (*/). Everything after the forward slash and asterisk (/*) symbol will be commented until it reaches the asterisk and forward slash (*/) symbol.
Example:
#include<stdio.h>
int main(){
/* This is an example for
Multi-Line Comment*/
printf("Welcome To C Tutorial");
return 0;
}
Output:
Welcome To C Tutorial
Leave a Comment