Single Line Comment
In C++ Single line comments are represented as // double forward slash. It applies comments to a single line only. The compiler ignores any text after // and it will not be executed.
Syntax:
// Single line comment
Example:
C++
// C++ Program to demonstrate single line comment #include <iostream> using namespace std; int main() { // Single line comment which will be ignored by the // compiler cout << "GFG!" ; return 0; } |
Output
GFG!
C++ Comments
Comments in C++ are meant to explain the code as well as to make it more readable. When testing alternative code, it can also be used to prevent execution. The purpose of the comments is to provide information about code lines. Programmers commonly use comments to document their work.
Contact Us