0
what is the use of “comments” if compiler ignores it?
14 Answers
+ 5
They exist so that other people (including future you) can understand how code works and how to use it.
Example 1:
void check_user_input(char &c); //looks for user input and stores the next character in c. If there has not been user input c will be 0.
Example 2:
bool tabs_to_spaces(char *from, char *to)
{
bool a = false;
for (int i = 0; i < strlen(from); ++i)
if (from[i] == '\t' ) {
a =true;
break;
}
if (a)
return false; //no need for conversion, we return false to signal this
...
}
+ 3
Aksh97 Yes, I label the code with comments, so that other developers understands the code easily.
+ 3
Try replacing -
cout<<"sum";
with-
cout<<sum;
+ 2
it serves the use for either notes to yourself... about the code... if you need it.... and when other developers are working on your code it can help them in debugging and understand the flow of what is going on... or the requirements. .. or why something may have been coded a certain way. etc.....
+ 2
does it mean we are “Labelling” a code. To identify in future ( what is this code about ).
+ 1
well, you could say that... I don't know if I would call it that.... imo
It is one part of a good coding practice when used wisely. :)
+ 1
thanks
i just started cpp
and not very well with english so couldn’t express the way i want to
+ 1
thanks
+ 1
#include <iostream>
using namespace std;
int main()
{
int a = 42;
int b = 56;
int sum = a + b;
cout<< "sum";
return 0;
}
+ 1
output: sum
+ 1
can you help me
no output from this
+ 1
want to calculate sum of two integers
+ 1
👍😅
0
Aksh97 , No issues. All the best. 👍