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

Contenido del Curso

Introduction to C++

Introduction to C++

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

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:

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

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 1. Capítulo 4
some-alt