C++ Comments
Comments
can be used to explain C++ code, and to make it more readable. It can also be
used to prevent execution when testing alternative code. Comments can be
singled-lined or multi-lined.
Single-line comments start with two
forward slashes (//).
Any
text between // and the end of the line is ignored by the compiler
(will not be executed).
Single line Program:
#include
<iostream>
using namespace std;
int main() {
// This is single line comment
cout << "Hello World!";
return 0;
}
Output:
Hello World
Multi-line
comments start with /* and ends with */.
Any
text between /* and */ will be ignored by the compiler:
Multi-Line program:
#include
<iostream>
using namespace std;
int main() {
/* this is multi-line comments and print
hello world */
cout << "Hello World";
return 0;
}
Output:
Hello World
No comments:
Post a Comment