How to write comments and their types in C++ - ProgrammerTech
Language:

Search

How to write comments and their types in C++

  • Share this:
How to write comments and their types in C++

Comments in C++

Comments In Programming In Programming All written words must be consistent with the programming language in which we are writing.

But what if we want to write a joke in the middle of the code or perhaps a translation of a specific word so that the program does not read it and is considered just a side draft. In all programming languages, the notes feature is available in the middle of the code, what is known as Comments. Comments can be written, for example, to remember why you wrote a specific code somewhere.

There are two types of Comments in programming languages:

  1. Single comments in one line.
  2. Comments on multiple lines.

 

Comments are single in one line

Comments are written in one line by writing two slash tags next to each other // and writing the comment after it as the following code

#include <iostream>
using namespace std;
int main()
{
    //This is a one-line comment that is not read by the commentator
    cout << "Hello world!" << endl;
    return 0;
}

But if we write words without putting the slash mark twice, this is not considered a comment, and the editor will consider it a programming error and put a flag next to it.

 

Multi-line comments

This type of Comments is done by writing the slash symbol and then the asterisk /* and then writing the comment we want with lines. Multiple then at the end we lock it with the star symbol and then slash */ and here it indicates the end of writing the comment or note.

#include <iostream>
using namespace std;
int main()
{
        /*
Here we are writing comments or observations
Multiple lines two lines three four lines.
Welcome to the Programmer Tech website to learn
Programming languages from scratch
        */
    cout << "Hello world!" << endl;
    return 0;
}

We also note that between /* and */ is considered a note and is not read by the language translator or interpreter.

From your view of the editor used by CodeBlocks, it makes the comments color gray, while the rest of the code commands have different colors, whether the print function has a color or a reserved word has another color.


Muhammad Alush

Muhammad Alush

إسمي محمد تركي العلوش من سورية من ريف حلب الشرقي 1994, محب للتقنية و التعلم الذاتي, و جميع خبراتي تعلمتها ذاتياً, و اللغات البرمجية التي أتقنها هي html, css, javascript, php, c, python بالإضافة إلى حبي الكبير لمجال الشبكات.

موقعي programmer-tech.com