What is comment in C?
In C, a comment is a piece of text in code that is not executed when the program is executed.
Comments are used to provide explanations, and keep documentation, or notes within the code for future reference and code understanding.
C supports two types of comments: single-line comments and multi-line comments.
Lines between /* and */ is treated as multi-line comments by C compiler.
Adding multi-line comments in C
To create a multi-line comment, add /*
to begin a multi-line comment and */
to end it.
xxxxxxxxxx
/*
This is an example
of multiple lines comment in C
*/
In the following example, the multiple lines
This is an example
of multiple lines
comment in C
is placed between /*
and */
. It creates a multi-line comment. C compiler will ignore the lines as comment and it will not have any effect on the execution of the program.
Example of C Multi-line Comments
xxxxxxxxxx
#include <stdio.h>
int main() {
/*
This is an example
of multiple lines
comment in C
*/
printf("Use /* to begin a multiple lines comment and */ to end it.");
// Anything between /* and */ is treated as a comment
return 0;
}
Output of the above example
Use /* to begin a multiple lines comment and */ to end it.
The output does not contain the commented lines.