Comments add explanations for people reading source code. They are not executable C statements. Use // for a comment that continues to the end of the line, or /* ... */ for a block comment.
int num = 10; // Store an integer value
// Display the value
printf("%d\n", num);
Everything after // on that source line is part of the comment.
/* This is a block comment.
It can continue across
multiple source lines. */
#include <stdio.h>
int main(void) {
double number = 17.873; // Declare and initialize
/* Display the value with
three digits after the decimal point. */
printf("number = %.3f\n", number);
return 0;
}
Output
number = 17.873
Standard C block comments do not nest. This should not be used:
/* outer comment /* inner comment */ rest of text */
The first */ ends the block comment, leaving the remaining text to be parsed as source code.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.