why do we comments in variables | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 1

why do we comments in variables

#include <iostream> using namespace std; int main() { int myVariabe = 10; cout <<"myVariabe"; } // Output 10

12th May 2017, 11:13 AM
opoku annor prince
opoku annor prince - avatar
10 ответов
+ 14
#include <iostream> using namespace std; int main() { int myVariabe = 10; cout << "myVariabe"; } // Output myVariabe 〰〰〰〰〰〰〰〰〰〰〰〰 Add to the @Mohammad answer, that your comment is incorrect, the output in your code will be "myVariabe", if you want "10" as output... remove the double quote from "myVariabe".
12th May 2017, 11:29 AM
Maz
Maz - avatar
+ 10
comments are used to make the program readable and clear to others when read your program to understand what it do and how, and to you so that you can make update easly after a period of time if needed.
12th May 2017, 11:26 AM
Mohammad Dakdouk
Mohammad Dakdouk - avatar
+ 4
Aside from the output being wrong as @Maz pointed out. I would comment similar variables if I have a lot of them, for what they're related to. It makes it super easy to know what they're used for whether or not you wrote the code. The names makes some of these variables obvies, but when it's not so obvies it does help to comment. Example: // -- players stats below -- int hp; uint xp; float attackSpd; float movementSpd; // -- end players stats -- // -- UI -- Canvas poorlyNamed; // for all player UI Image img; // hp bar
12th May 2017, 2:40 PM
Rrestoring faith
Rrestoring faith - avatar
+ 1
@kyle, thats a bad practice. You should declare variables only right before you use them. Otherwise you have stuff on the stack or in the registers when they dont need to be, which effects performance
12th May 2017, 11:45 AM
aklex
aklex - avatar
+ 1
figures. I only started doing that because various tutorials told me I should, now I have to break the habit lol
12th May 2017, 10:48 PM
LordHill
LordHill - avatar
0
I don't comment variables. I name them properly. I also try to declare them in groups. its, floats, etc
12th May 2017, 11:38 AM
LordHill
LordHill - avatar
0
I thought it was the norm to declare my variables at the beginning of my class and then define them as needed.
12th May 2017, 12:00 PM
LordHill
LordHill - avatar
0
We marked for other programmer. If they read our code , thry can more understand.
12th May 2017, 12:32 PM
Ye Htet Kyaw
Ye Htet Kyaw - avatar
0
@Kyle for some prgorammers that dont understand how the stack and registers work, yes. But its a bad habbit
12th May 2017, 10:05 PM
aklex
aklex - avatar
- 1
kk
12th May 2017, 11:32 AM
opoku annor prince
opoku annor prince - avatar