Comments in C
Comments in C
Comments in C
Using comments in a C program
increases the readability of the code.
You must intersperse the code with
comments at appropriate places. As
far as the compiler is concerned, the
comments are ignored. In C, the
comments are one or more lines of
text, that the compiler skips while
C Programming Tutorial
building the machine code.
https://www.tutorialspoint.com/cprogramming/c_comments.htm 1/7
6/16/24, 10:57 AM Comments in C
if (a % 2 == 0){
printf("%d is Even\n", a);
} else {
printf("%d is Odd\n", a);
}
(a % 2 == 0) ? printf("%d is Even\n", a) :
Types of Comments in C
In C, there are two types of
comments −
Single-line comments
Multi-line comments
Single-line Comment in C
https://www.tutorialspoint.com/cprogramming/c_comments.htm 2/7
6/16/24, 10:57 AM Comments in C
Syntax of Single-line C
Comment
//comment text
Example: Single-line
Comment in C
https://www.tutorialspoint.com/cprogramming/c_comments.htm 3/7
6/16/24, 10:57 AM Comments in C
return 0;
}
Output
Multi-line Comment in C
Syntax of Multi-line C
Comment
https://www.tutorialspoint.com/cprogramming/c_comments.htm 4/7
6/16/24, 10:57 AM Comments in C
…..
…..
Comment ends here*/
For example −
/*
Example of a multi-line comment
program to print Hello World
using printf() function
*/
/* headers */
#include <stdio.h>
#include <math.h>
/* main function */
int main(){
https://www.tutorialspoint.com/cprogramming/c_comments.htm 5/7
6/16/24, 10:57 AM Comments in C
/* variable declaration */
float side = 5.50;
/* calling function */
float area = area_of_square(side);
printf("Side = %5.2f Area = %5.2f", side
return 0;
}
Output
https://www.tutorialspoint.com/cprogramming/c_comments.htm 6/7
6/16/24, 10:57 AM Comments in C
https://www.tutorialspoint.com/cprogramming/c_comments.htm 7/7