Saturday, April 19, 2025

C++ Comments

Comments in programming can be short or simple explanations what specific source code do.

We use them to explain ourselves and our colleagues what our code is doing because someone (including us) can read comments/source even decades after programs is completed.

Usually, it's smart idea to keep comment short and to the point.

Comments will not influence execution of source code, they will just sit there if we need to read them.

Authors of programming languages have different symbols to start and end comment section, and in C++ we use // to star one line comment, and /* and */ pair to start and end multiline comment section.

Comments are useful because we can write programs that will get into our other programs and extract comments as documentation.

We can transfer/extract that internal "documentation" in different formats, HTML, pdf, txt and so on, if needed. 

#include <iostream>

using namespace std;

int main() {

    int multiArr[2][3] = {{2, 5, 6}, {4, 7, 9}};

    //This is First One Line Comment

    //This code down there will not run, it's multiline comment section

    /*
    cout << multiArr[0][0] << endl;
    cout << multiArr[0][1] << endl;
    */

    //This is Second One Line Comment

    cout << "This will be printed" << endl;
    cout << "This too: " << multiArr[0][2] << endl;

    return 0;

}

No comments:

Post a Comment

Tkinter Introduction - Top Widget, Method, Button

First, let's make shure that our tkinter module is working ok with simple  for loop that will spawn 5 instances of blank Tk window .  ...