Comments in C

 

💻 Comments in C (Easy Explanation)

In C (developed by Dennis Ritchie), comments are used to write notes or explanations inside the program.

👉 These are ignored by the compiler (they do not affect the output)


🔹 What are Comments? 🤔

Comments are used to:

  • Explain code 📖
  • Make program easy to understand
  • Help other programmers

🔹 Types of Comments in C

🔸 1. Single-Line Comment (//) ✏️

👉 Used for writing comment in one line

✅ Example:

#include <stdio.h>

int main() {
// This is a single-line comment
printf("Hello");
return 0;
}

🔸 2. Multi-Line Comment (/* */) 🧾

👉 Used for writing comments in multiple lines

✅ Example:

#include <stdio.h>

int main() {
/* This is a
multi-line comment */
printf("Hello");
return 0;
}

🔹 Important Rules ⚠️

✔ Comments are not executed
✔ Used only for understanding code
✔ Can be written anywhere in program


❗ Invalid Example

/* This is wrong // mixing comments */

👉 Always close multi-line comment properly ❌


🔹 Real-Life Example 🤔

👉 Comments = Teacher ke notes 📚
👉 Code = Exam answers

Notes help samajhne me, but exam me count nahi hote 😄


🔹 Example with Proper Comments 🧠

#include <stdio.h>

int main() {
int a = 10; // storing value

/* printing the value of a */
printf("%d", a);

return 0;
}

🔹 Why Comments are Important? 🔥

  • Makes code readable 👀
  • Helps in debugging 🛠️
  • Useful for teamwork 🤝

🔹 Final Summary 📝

  • // → single-line comment
  • /* */ → multi-line comment
  • Ignored by compiler
  • Used for explanation only

Comments

Popular posts from this blog

Introduction to Computer

History of Computer

Computer Generation