0

what is the use of “comments” if compiler ignores it?

9th Jun 2018, 12:24 PM
Aksh97
Aksh97 - avatar
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 ... }
9th Jun 2018, 12:43 PM
Vlad Serbu
Vlad Serbu - avatar
+ 3
Aksh97 Yes, I label the code with comments, so that other developers understands the code easily.
9th Jun 2018, 1:13 PM
Sachin Artani
Sachin Artani - avatar
+ 3
Try replacing - cout<<"sum"; with- cout<<sum;
9th Jun 2018, 1:22 PM
Sachin Artani
Sachin Artani - avatar
+ 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.....
9th Jun 2018, 12:44 PM
laura
+ 2
does it mean we are “Labelling” a code. To identify in future ( what is this code about ).
9th Jun 2018, 12:49 PM
Aksh97
Aksh97 - avatar
+ 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. :)
9th Jun 2018, 1:12 PM
laura
+ 1
thanks i just started cpp and not very well with english so couldn’t express the way i want to
9th Jun 2018, 1:16 PM
Aksh97
Aksh97 - avatar
+ 1
thanks
9th Jun 2018, 1:17 PM
Aksh97
Aksh97 - avatar
+ 1
#include <iostream> using namespace std; int main() { int a = 42; int b = 56; int sum = a + b; cout<< "sum"; return 0; }
9th Jun 2018, 1:20 PM
Aksh97
Aksh97 - avatar
+ 1
output: sum
9th Jun 2018, 1:20 PM
Sachin Artani
Sachin Artani - avatar
+ 1
can you help me no output from this
9th Jun 2018, 1:20 PM
Aksh97
Aksh97 - avatar
+ 1
want to calculate sum of two integers
9th Jun 2018, 1:22 PM
Aksh97
Aksh97 - avatar
+ 1
👍😅
9th Jun 2018, 1:23 PM
Aksh97
Aksh97 - avatar
0
Aksh97 , No issues. All the best. 👍
9th Jun 2018, 1:18 PM
Sachin Artani
Sachin Artani - avatar