C++ Comments

C++ Comments


Every comment-program is the explanatory statement that we also include in the C++ code. The comment statements can help anyone to understand each processing step by step by reading from the source code. All programming languages always allow for some forms of comments, but in different forms of each programming language.

The C++ comments support single-line and multiple-line. All characters must be available inside any comment and always ignored by the compiler of C++.

Normally, C++ comments start with /* and end with */. For example:
/*This is my comment in single-line*/

/*This my comment in multiple-line
*C++ can also support for multiple-line
*/

We can also extending the comment at the of each line with //. For example:

#include<iostream>
using namespace std;
main(){
 cout<<"Hello World!"; //Prints Hello World!
return 0;
}
When compiling the source code above, the compiler will ignore //Prints Hello World!, So the final executable result will be produced the by following:

Hello World!

Within a /* and */ comment and a // character have no special meaning. Mean that all of this, you can 'hideaway' just one kind of comment. For example, I have shown above.

More practices by the following examples:

Example 1

Example 1 of Comment in C++

#include<iostream>
using namespace std;
main(){
cout<<"What\'s the meaning of ATM?\n"; /*Prints What's the meaning of ATM - Single-Line Comment*/
cout<<"Automated Teller Machine\n"; //Prints Automated Teller Machine - Single-Line Comment
cout<<"-----\n";
/*If you want to know more
*please let's us know
*- Multiple-Line Comment
*/
cout<<"Please make your own examples!\n";
cout<<"Thank you!\n";
return 0;
} 

Example 2

#include<iostream>
using namespace std;
int main()
{
   
    string a,b,c;
    /*input your name*/
    cout<<"Enter Name: ";cin>>a;
   
    //input your gender
    cout<<"Enter Gender : ";cin>>b;
   
    //input your dob
    cout<<"Date of Birth : ";cin>>c;
    return 0;
   
}

Download this text as pdf file

>> Learn more about C++

Comments

Popular posts from this blog

ភាសាកម្មវិធី C++៖ អថេរ ឬអញ្ញាតិ

How to download and install Cambridge Advanced Learner's Dictionary_Fourth Edition-CALD4