+ 1
why do we comments in variables
#include <iostream> using namespace std; int main() { int myVariabe = 10; cout <<"myVariabe"; } // Output 10
10 Respuestas
+ 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".
+ 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.
+ 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
+ 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
+ 1
figures. I only started doing that because various tutorials told me I should, now I have to break the habit lol
0
I don't comment variables. I name them properly. I also try to declare them in groups. its, floats, etc
0
I thought it was the norm to declare my variables at the beginning of my class and then define them as needed.
0
We marked for other programmer.
If they read our code , thry can more understand.
0
@Kyle for some prgorammers that dont understand how the stack and registers work, yes. But its a bad habbit
- 1
kk