Labs ICT
โญ Pro Login

Comments

Comments are parts of your code that the compiler ignores. They are there for you and other programmers. Think of them as sticky notes you leave in your code to remind yourself what something does or why you wrote it a certain way.

Single-Line Comments

Use // for comments that fit on one line. Everything after // on that line is ignored.

Multi-Line Comments

Use /* */ for comments that span multiple lines. Everything between the opening /* and closing */ is ignored, no matter how many lines it covers.

Comments in Action

#include <iostream>
using namespace std;

int main() {
  // This is a single-line comment
  cout << "Hello!"; // Comments can go after code too

  /* This is a
     multi-line comment.
     It can span several lines */
  cout << "World!";
  return 0;
}

Use comments wisely. Good comments explain why something is done, not what the code does. The code itself should already show what it does. If you find yourself writing comments that explain basic syntax, you might need to make your code clearer instead.

๐Ÿงช Quick Quiz

How do you write a single-line comment in C++?