Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Leer Comments | Basics
Introduction to C++

bookComments

Comments in programming are parts of code that are ignored. It’s a good rule to use them to improve the readability of your code with specific descriptions of what a certain part of the code does. Comments also help when you want to test a certain part of the program without deleting the other code.

To mark the line(or part of the line) as a comment, begin the respective string with //.

For example, in this case, the line which outputs the message "Hello!" will be ignored:

123456789
#include &lt;iostream&gt; using namespace std; int main() { &nbsp&nbsp&nbsp&nbsp // cout << "Hello! \n"; &nbsp&nbsp&nbsp&nbsp cout << "I love C++! "; &nbsp&nbsp&nbsp&nbsp cout << "Goodbye!"; &nbsp&nbsp&nbsp&nbspreturn 0; }
copy

This type of comment is also good for code explanation:

cout << "Goodbye!";  // Print the message

If you want the compiler to ignore several lines use multi-line comments. They start with /* and end with */:

123456789
#include &lt;iostream&gt; using namespace std; int main() { &nbsp&nbsp&nbsp&nbsp&nbsp/* cout << "Hello!"; &nbsp&nbsp&nbsp&nbsp cout << "I love C++! "; */ &nbsp&nbsp&nbsp&nbsp cout << "Goodbye!"; // Print the message &nbsp&nbsp&nbsp&nbsp return 0; }
copy
question-icon

The code must only print the message: "I have learned C++ basics!". Fill gaps in the code:

#include <iostream>
using namespace std;

int main() {
    
cout << "Hello!\n";
    cout << "World!\n";

    cout << "I have learned C++ basics! \n";
  Print the message
    return 0;
}
I’m learning C++!

Click or drag`n`drop items and fill in the blanks

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 1. Hoofdstuk 4

Vraag AI

expand

Vraag AI

ChatGPT

Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.

Awesome!

Completion rate improved to 3.33

bookComments

Veeg om het menu te tonen

Comments in programming are parts of code that are ignored. It’s a good rule to use them to improve the readability of your code with specific descriptions of what a certain part of the code does. Comments also help when you want to test a certain part of the program without deleting the other code.

To mark the line(or part of the line) as a comment, begin the respective string with //.

For example, in this case, the line which outputs the message "Hello!" will be ignored:

123456789
#include &lt;iostream&gt; using namespace std; int main() { &nbsp&nbsp&nbsp&nbsp // cout << "Hello! \n"; &nbsp&nbsp&nbsp&nbsp cout << "I love C++! "; &nbsp&nbsp&nbsp&nbsp cout << "Goodbye!"; &nbsp&nbsp&nbsp&nbspreturn 0; }
copy

This type of comment is also good for code explanation:

cout << "Goodbye!";  // Print the message

If you want the compiler to ignore several lines use multi-line comments. They start with /* and end with */:

123456789
#include &lt;iostream&gt; using namespace std; int main() { &nbsp&nbsp&nbsp&nbsp&nbsp/* cout << "Hello!"; &nbsp&nbsp&nbsp&nbsp cout << "I love C++! "; */ &nbsp&nbsp&nbsp&nbsp cout << "Goodbye!"; // Print the message &nbsp&nbsp&nbsp&nbsp return 0; }
copy
question-icon

The code must only print the message: "I have learned C++ basics!". Fill gaps in the code:

#include <iostream>
using namespace std;

int main() {
    
cout << "Hello!\n";
    cout << "World!\n";

    cout << "I have learned C++ basics! \n";
  Print the message
    return 0;
}
I’m learning C++!

Click or drag`n`drop items and fill in the blanks

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 1. Hoofdstuk 4
some-alt