0
C++ Variables ?
Good evening everyone. Just been doing some work with variables and after awhile have just started to grasp the concept of them. Can someone tell me how I would go about naming a variable ? Like; I would understand one better if someone wrote a couple out for me from a simple one to a more complicated variable, and label them so I would know where the variable type is as well as it's name and function. Also, does naming a variable effect it's function in anyway ? Again, thanks for your help. P.S Hope I'm keeping the more advanced programmers on their toes.
1 Answer
+ 1
variable names should describe the variable. for instance, if you have a variable that holds a name, you wouldn't call it age or donkey.. you would call it something like name or player. naming your variable doesn't effect it at all. here are some examples. consider a game..
int players = 2;
string playerOne = "Harry";
string playerTwo = "John";
int p1Score = 0;
int p2Score = 1204;
First I made a variable to tell how many players there are. Then I made 2 variables to store their names. Finally I made 2 variables to store their scores. Notice I tried to name them something relevant to what they are. doesn't matter what you name them, but when you want to call on them later it will be easier to know what your dealing with.