💬 C++ Comments – Single-Line and Multi-Line Examples
Comments are your way of talking to your future self (or teammates). They’re ignored by the compiler, but loved by humans! 🧠❤️
🔹 Why Use Comments?
- Explain what your code does
- Make your code easier to understand
- Temporarily disable parts of code during testing
📝 Types of Comments in C++
C++ supports two types of comments:
- Single-line comment: Starts with
//
- Multi-line comment: Starts with
/*
and ends with*/
🔧 Example: C++ Comments
#include <iostream> using namespace std; int main() { // This is a single-line comment cout << "Hello with comments!" << endl; /* This is a multi-line comment. You can write anything here and it will be ignored! */ return 0; }
🎯 Output
Hello with comments!
🧠 Quick Tips
- Use comments to describe complex logic.
- Don’t over-comment obvious things — your future self might thank you 😅
- Great code + great comments = excellent developer! 💪