0

Why is it called a variable?

I didn't quite understand the concept. Why does it have to be integer at the front?

26th Jan 2017, 7:28 AM
Shahriar Azad
Shahriar Azad - avatar
5 Respuestas
+ 10
Variables are objects in which the values they contain are subjected to change. int x = 1; This is an integer type variable of initial value 1. You can change the value of variable x to 2 by doing x = 2;
26th Jan 2017, 7:33 AM
Hatsy Rei
Hatsy Rei - avatar
+ 10
They're called variables because their contents can vary, and be changed as many times as you need. The int at the front means the variable is meant to contain an integer/whole number. The data type you use tells the computer how to interpret what you store in it. Ex: There's a difference between, say, 81 as a whole number, and "81" as a string/text.
26th Jan 2017, 7:40 AM
Tamra
Tamra - avatar
+ 1
Thx
26th Jan 2017, 8:05 AM
Shahriar Azad
Shahriar Azad - avatar
+ 1
Imagine you have 4 empty boxes at home, and you need them to pack your stuff to move somewhere. To make things easy for yourself, you mark these boxes so that you know exactly what will be in them when you finally close them. You mark the first box as "shirts", second as "shoes", third as "shocks" and the fourth one as "trousers". Now that your boxes are marked, you not only know where to place your clothes in but you also know where you shouldn't put your clothes in. Now think of the box as a variable and the markers as data types. The box alone is nothing without its marker, that's why it needs a marker so that you know what you can and cannot put in it. Example: (Java) int box1; //you can only place whole numbers in here String box2; //you can only place characters/text in here boolean box3; //you can only place boolean values in here (true or false) I hope this makes it more clear for you, happy coding ;)
26th Jan 2017, 8:27 AM
Ghauth Christians
Ghauth Christians - avatar
0
Thank you gain Christians.
26th Jan 2017, 8:34 AM
Shahriar Azad
Shahriar Azad - avatar