Comments are generally used as hints that developers can add to make their programs easier to read and understand. They are fully ignored by compilers.
There are two ways for commenting:
1 2 3 |
// single line comment /* */ multiple line comments |
For Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
#include <iostream> using namespace std; int main() { int a, b; a = 2; b = 2; //codinz :) //the sum of a and b cout << "a + b = " << (a + b) << endl; /* the sum of a and b */ cout << "a + b = " << (a + b) << endl; return 0; } |
Why use Comments?
If we write comments on our code, it will be easier for us/developers to understand the code in the future.