
Comments in C
In C, comments are used to explain code and make it more readable — especially useful for documentation, debugging, or future you! ??
?? Types of Comments in C
? 1. Single-line Comment
Use //
to comment everything after it on the same line.
int main() { // This prints Hello, World! printf("Hello, World!\n"); return 0;}
? 2. Multi-line Comment
Use /* ... */
to write comments over multiple lines.
#include <stdio.h>int main() { /* This is a multi-line comment. You can explain complex logic here. */ printf("Multi-line comment example\n"); return 0;}
?? Notes
You can’t nest multi-line comments in C.
/* Outer comment /* Inner comment */ // ? Not allowed!*/
Comments are ignored by the compiler and have no effect on the actual program output.
? Best Practices
Use comments to explain why, not just what.
Don’t overuse — write clean, self-explanatory code.
Keep comments up to date if code changes.