A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/cpp/cpp-comments/ below:

C++ Comments - GeeksforGeeks

C++ Comments

Last Updated : 23 Jul, 2025

Comments in C++ are meant to explain the code as well as to make it more readable. Their purpose is to provide information about code lines. When testing alternative code, they can also be used to prevent execution of some part of the code. Programmers commonly use comments to document their work.

Example:

C++
#include <iostream>
using namespace std;

int main() {
  
    // A comment to provide information about below line
    // Print statement
    cout << "GFG!";
    return 0;
}

Explanation: Line started by '//' is a comment line which is not compiled by the compiler.

In C++ there are two types of comments:

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.

Example:

C++
#include <iostream>
using namespace std;

int main() {
  
    // Single line comment
    cout << "GFG!";
    return 0;
}

A multi-line comment can occupy many lines of code, it starts with /* and ends with */, but it cannot be nested. Any text between /* and */ will be ignored by the compiler.

Example:

C++
#include <iostream>
using namespace std;

int main() {
  
    /* Multi line comment which
       will be ignored by the compiler
    */
    cout << "GFG!";
    return 0;
}

Tip: Some IDEs provide shortcut to apply comments as well, such as:

Comments in C++ are used to summarize an algorithm, identify a variable's purpose, or clarify a code segment that appears unclear. Comments are also used for:

As a part of the compiler, the Lexical Analyzer scans the characters and transforms them into tokens with no passing of the commented text to the parser. Since Comments do not contribute to the functionality of the program they are simply omitted at the time of compilation. Accordingly, we can understand that comments are just text in programs that are ignored by the compiler.



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4