Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте 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++!

Натисніть або перетягніть елементи та заповніть пропуски

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 4

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

Awesome!

Completion rate improved to 3.33

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++!

Натисніть або перетягніть елементи та заповніть пропуски

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 4
some-alt