Welcome to Mobilarian Forum - Official Symbianize forum.

Join us now to get access to all our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, and so, so much more. It's also quick and totally free, so what are you waiting for?

1.2

Alexhost
M 0

marckos

Abecedarian
Member
Access
Joined
Jun 25, 2014
Messages
195
Reaction score
31
Points
18
grants
₲9,107
10 years of service
Types of comments

A comment is a line (or multiple lines) of text that are inserted into the source code to explain what the code is doing. In C++ there are two kinds of comments.

The // symbol begins a C++ single-line comment, which tells the compiler to ignore everything to the end of the line. For example:

1
cout << "Hello world!" << endl; // Everything from here to the right is ignored.
Typically, the single line comment is used to make a quick comment about a single line of code.

1
2
3
cout << "Hello world!" << endl; // cout and endl live in the iostream library
cout << "It is very nice to meet you!" << endl; // these comments make the code hard to read
cout << "Yeah!" << endl; // especially when lines are different lengths
Having comments to the right of a line can make the both the code and the comment hard to read, particularly if the line is long. Consequently, the // comment is often placed above the line it is commenting.

1
2
3
4
5
6
7
8
// cout and endl live in the iostream library
cout << "Hello world!" << endl;

// this is much easier to read
cout << "It is very nice to meet you!" << endl;

// don't you think so?
cout << "Yeah!" << endl;
The /* and */ pair of symbols denotes a C-style multi-line comment. Everything in between the symbols is ignored.

1
2
3
/* This is a multi-line comment.
This line will be ignored.
So will this one. */
Since everything between the symbols is ignored, you will sometimes see programmers
 
Top Bottom