The comment statement is not executable. Comments are like helping text in C program and they are ignored by the compiler and it is very helpful to understand the program easily. There are two types of comment in C program.
1.Single line comment
- It can be Placed anywhere in C program
- Single line comment starts with " // "
- It can't be split over Multiple lines like Multi line comment
- Any symbols written after "//" will be ignored by C compiler.
// Title : Learn C
// Author : Mohamed Ushman
#include <stdio.h>
int main()
{
printf("Learn C :)"); // Single line comment
return 0;// Until the end of line will be ignored by C compiler
}
2. Multi line comment
- It can be Placed anywhere in C program
- Single line comment starts with "/*" and ends with "*/"
- It can be split over Multiple lines
- It can be used like Single line comment
/*
Title : Learn C
Author : Mohamed Ushman
*/
#include <stdio.h>
int main()
{
printf("Learn C :)"); /* It can be used like Single line comment */
/*-----------------------------------------------------------------
printf("Learn C program"); Ignored By C Compiler
------------------------------------------------------------------*/
return 0;
}
Different way of using comments
We can use comment to specify variables and some operation like addition, subtraction, etc.., .Example:
/*********************************
* Title : Learn C
* Author : Mohamed Ushman
*********************************/
#include <stdio.h>
int main()
{
int a=5,b=5;
int c; // To display output
c=a+b; // Adition
/*
c=a-b; // Subtraction
*/
printf("Value of c=%d",c);
return 0;
}