Comments in C

Comments are notes written in source code for humans. The compiler does not treat them as executable program instructions.

Single-line comment

// This is a single-line comment
int age = 20; // stores the age

 

Multi-line comment

/*
This is a multi-line comment.
It can contain several lines.
*/

 

Program with comments

#include <stdio.h>

int main() {
// Store two numbers
int a = 10;
int b = 20;

/* Add the numbers
and display the result */
int sum = a + b;

printf(“Sum = %d”, sum);

return 0;
}

 

OUTPUT
Sum = 30

 

⭐ EASY TIP: Use comments to explain why something is being done, especially when the logic is not obvious.
Scroll to Top