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

Зміст курсу

Introduction to C++ | Mobile-Friendly

Introduction to C++ | Mobile-Friendly

1. Basics
2. Variables
3. Conditional Statements
4. Loops
5. Intro to Arrays

Comments

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&nbsp&nbspreturn 0; }

This type of comment is also good for code explanation:

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; }
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 have learned C++ basics!

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

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

Секція 1. Розділ 4
We're sorry to hear that something went wrong. What happened?
some-alt