💬 C Comments

Comments in C are little notes you leave inside your code for yourself or other programmers. They help explain what the code does, but they are completely ignored by the compiler. Think of them as sticky notes for your future self! 📝

🔹 Types of Comments in C

There are two main types of comments in C:

  • Single-line Comments: Start with //
  • Multi-line Comments: Start with /* and end with */

📝 Example: C Comments in Action

This example shows both types of comments used in a simple C program.

#include <stdio.h>

int main() {
    // This is a single-line comment
    printf("Learning comments in C!\n");

    /* This is a 
       multi-line comment 
       explaining the next line */
    printf("Comments make code easy to understand.\n");

    return 0;
}
  

Try It Now

✅ Why Use Comments?

  • To explain what complex parts of code do.
  • To temporarily disable parts of code while testing.
  • To help others (or future you!) understand your logic.

⚠️ Best Practices

  • Don’t over-comment obvious code.
  • Use comments to clarify **why**, not just **what**.
  • Keep them short and helpful.

🧪 Practice Challenge

Write a program that uses both single-line and multi-line comments. Try explaining what your printf statement does using a comment!