C Tutorial



COMMENTS IN C


Comments in C

Comments in C are lines in the code that are not executed by the compiler. They are used to explain the code, increase readability, and make it easier to understand later.

๐Ÿ—’๏ธ Note: Comments are ignored during program execution.

๐Ÿ’ฌ Types of Comments in C

  • Single-line Comment: Starts with // and continues to the end of the line.
  • Multi-line Comment: Starts with /* and ends with */.

๐Ÿงช Example

#include <stdio.h>

int main() {
    // This is a single-line comment

    /* This is a
       multi-line comment */

    printf("Hello, World!\\n"); // Prints message
    return 0;
}
  

โœ… When to Use Comments

  • To describe what the code does
  • To leave notes or reminders
  • To temporarily disable a line of code
๐Ÿ’ก Tip: Don't overuse comments. Your code should be simple and self-explanatory.

โŒ Common Mistakes

  • ๐Ÿšซ Unclosed multi-line comment: /* ... without ending */
  • ๐Ÿšซ Using // for multi-line text (older C compilers may not support it)

๐Ÿ“ Try It Yourself

  1. Add a single-line comment above a printf() statement.
  2. Write a multi-line comment explaining what the main() function does.

๐ŸŒŸ Enjoyed Learning with Us?

Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!

Leave a Google Review