In C programming, comments are used to add explanations or notes within the code. These notes are not executed by the compiler. Their sole purpose is to make the code easier to read and understand for programmers.

Whether you’re a beginner or a seasoned coder, using comments wisely is crucial for maintaining clean and organized code.
Why are Comments Important?
Here are a few reasons why comments are vital in programs:
- Improves readability of complex logic.
- Helps teams collaborate more effectively.
- Useful during debugging or testing to disable certain code lines.
- Serves as reminders for future code updates.
Types of Comments:
C supports two main types of comments:
- Single-Line Comments
- Multi-Line Comments
1. Single-Line Comments
Single-line comments start with //
. They are used to explain a specific line or a short piece of code.
Syntax:
// This is a single-line comment
Example:
#include <stdio.h> int main() { // Printing a welcome message printf("Hello, World!"); return 0; }
2. Multi-Line Comments
Multi-line comments start with /*
and end with */
. These are ideal when you need to explain a block of code or add detailed information.
Syntax:
/* This is a multi-line comment. It can span multiple lines. */
Example:
#include <stdio.h> int main() { /* This program demonstrates the use of multi-line comments in C. */ printf("Learning C is fun!"); return 0; }
Best Practices:
- Keep comments clear and concise.
- Use comments to explain “why”, not just “what”.
- Avoid writing obvious comments (like
// prints hello
). - Always update comments when the code changes.
Conclusion
Comments in C are not just about writing notes; they are an essential part of clean and maintainable code. By using single-line and multi-line comments properly, you can make your C programs easier to understand, modify, and debug.
Interview Questions:
1. What are the types of comments supported in C?(Infosys)
Answer:
C supports two types:
- Single-line comments: Begin with
//
and continue to the end of the line. - Multi-line comments: Enclosed between
/*
and*/
, and can span multiple lines.
2. Can we nest multi-line comments in C?(Wipro)
Answer:
No, nested multi-line comments are not allowed in C. If you try to nest them, it will result in a compilation error. C does not support nested block comments like some modern languages.
3. How can comments be helpful during debugging and testing?(TCS)
Answer:
Comments are useful for temporarily disabling code without deleting it. During debugging or testing, developers may comment out sections of code to isolate issues. This helps track down bugs without permanently removing logic.