Single-line and multi-line comments in the code
Add comments to the code
C Allows us to add comments to the code in two ways.
A single-line comment start with //
and ends at the end of the current line.
A multi-line comment starts with /*
and ends on some later line with */
.
This can be used to add explanation to the developers and maintainers of the code and also to temporarily disable some of the code.
#include <stdio.h>
// This is a comment
int main() {
printf("Hello "); // This is a comment too
// We don't want the following line of code to be included:
// printf("Hello World!\n");
printf("World");
/*
A multi-line comment
With a beginning and an end.
*/
printf("!\n");
}
$ gcc comments.c
$ ./a.out
Hello World!
//
'/*'