C++ Comments
C++ Comments
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
*/
/*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:using namespace std;
main(){
cout<<"Hello World!"; //Prints Hello World!
return 0;
}
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;
}
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;
}
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;
}
Comments
Post a Comment