C++ Comments

Comments in C++ are quite easy to understand and are just for your clarity. They are ignored by the compiler and are not executed. C++ comments in one line begin with two slashes '//'. For example-

//Program to print 'Hello World!'
#include 
using namespace std;
int main()
{
cout<<"Hello World!";
return 0;
}

You can write comments in multiple lines by either adding '//' before each line or you can begin it by adding '/*' at the start and ending by adding '*/' at the end. For example;

/*This is a comment
in two lines*/
#include 
using namespace std;
int main()
{
cout<<"Hello World!";
return 0;
}

Comments are ignored by the compiler and are only used for clarity of the code to make it more understandable for the user. It is your choice if you want to put comments in a program or not.

That is all for this post. Follow my blog to know more about coding languages.

Regards,
Aarav Iyer

References:
(1)
https://www.w3schools.com/cpp/cpp_comments.asp

Aarav Iyer

I am a technology and programming enthusiast, currently a high school student. I also love drawing and am fairly interested in aeronautics and astrophysics. My favourite pastimes are reading books, blogging and skywatching with my telescope.

Post a Comment

Previous Post Next Post