capypad
0 day streak
cpp / beginner
Snippet

Comments: Documenting Your Code

Comments explain code to human readers and are ignored by the compiler. Single-line comments use // and comment everything after on that line. Multi-line comments use /* */ and can span several lines. Good comments help others understand your logic.

snippet.cpp
cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
using namespace std;
 
int main() {
// This is a single-line comment
int score = 100;
/* This is a
multi-line comment
spanning three lines */
cout << "Score: " << score << endl;
return 0;
}
Breakdown
1
// This is a single-line comment
Compiler ignores everything after // on this line
2
/* This is a multi-line comment */
Everything between /* and */ is ignored by compiler