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 <iostream> using namespace std; int main() {      // cout << "Hello! \n";      cout << "I love C++! ";      cout << "Goodbye!";     return 0; }
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 <iostream> using namespace std; int main() {      /* cout << "Hello!";      cout << "I love C++! "; */      cout << "Goodbye!"; // Print the message      return 0; }
Kiitos palautteestasi!
Kysy tekoälyä
Kysy tekoälyä
Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme
Awesome!
Completion rate improved to 3.33
Comments
Pyyhkäise näyttääksesi valikon
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 <iostream> using namespace std; int main() {      // cout << "Hello! \n";      cout << "I love C++! ";      cout << "Goodbye!";     return 0; }
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 <iostream> using namespace std; int main() {      /* cout << "Hello!";      cout << "I love C++! "; */      cout << "Goodbye!"; // Print the message      return 0; }
Kiitos palautteestasi!