Comments
Comments are used by the programmer to make the code understandable so that it can be improvised later and to make it more readable. It can also be used to prevent execution when testing alternative code.
There are two ways to write Comments: singled-lined or multi-lined.
Single line comments
Single-line comments are initiated with two forward slashes (//). This comments the entire line after the two slashes.
Example:
#include <iostream>
using namespace std;
int main() {
// This is a comment and won't be executed
cout << "Demo Code";
return 0;
}
Output:
Demo Code
Multi Line comments
Multi-line comments start with /* and ends with */
The text in between both of these will not be executed by the compiler. Hence comments can we written in multiple lines
Example:
#include <iostream>
using namespace std;
int main() {
/*This is a multiple line comment
it will not be executed */
cout << "Demo Code";
return 0;
}
Output:
Demo Code