+ 1

Exactly what are variables? And why do i need them?

What do they do?

21st Jan 2017, 12:22 AM
Jacob
8 ответов
+ 2
Variables are used to store data. They are actually quite useful. For example, you could use variables to ask and print someone's name in your game. Obdviously you could use variables for other things like the player's health in a game, or how many calories they have eaten that day if you are making a food tracking app. Variables are an extremely important thing to know and understand if you want to program with any type of app!
30th Jan 2017, 12:31 AM
Jacob Russell
Jacob Russell - avatar
+ 1
They store values, that's all there is to it. You can't really have a program without using and changing values, and to work with these values you use variables.
21st Jan 2017, 12:25 AM
Robobrine
Robobrine - avatar
0
But why do i need values?
21st Jan 2017, 12:26 AM
Jacob
0
Because everything a computer does is compare values and change values. That's how everything you see here is done. The values are stored somewhere in RAM, and to make accessing them and working with them easier for programmers most programming languages have variables. Of cores you can program without them (for example assembler programming or with languages that don't use variables like brainfuck), but then you have to keep track on your own where everything is stored. For any bigger program that's just way too inconvenient.
21st Jan 2017, 12:35 AM
Robobrine
Robobrine - avatar
0
Variables can store values. This is useful when you're doing a lot of math in your program. For example, you can store the output of 2+2 (4) in a variable called x. Then, you can modify x later in your program. For example x = x * 2.
21st Jan 2017, 3:41 AM
Will Lewis
Will Lewis - avatar
0
You need a place to store the values in your program. Lets say you write code to ask the user for their name. When they input their name, you have them store that in a variable. Their name is a value. You may want to make it Hello, when they run the program. Just like when you turn on the xbox live. Its greets you with your account name whenever you go online. That name is stored as a value in a variable.
22nd Jan 2017, 5:19 AM
Bryan Lopez
Bryan Lopez - avatar
0
So suppose you're working as a waiter for 15 dollars an hour but in addition people are giving you tips all the time, so you want to calculate your income for the day, complicated... why? because in the busy hours you're getting much more tips, so what you would want to do is to tell a computer like "calculate 8 times (15+T)" and then each hour you're gonna specify what T (tip) stands for... so, "T" is a variable!!!
22nd Jan 2017, 7:28 AM
Gavi
Gavi - avatar
0
Without variable can't working programming if you run simple addition program you should declare variable in your program int a=10; int b=39; int x: int x = a+b; like that
3rd Feb 2017, 9:01 PM
Anand Bachhav