What is the point of changing the value of the variable once it is declared? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is the point of changing the value of the variable once it is declared?

we declare first eg. int a=100; then we change the value in the next step. a=50. why is the reduced value displayed in the output. and what is the point of changing the values..?

26th Feb 2017, 8:16 AM
RAHUL PATIDAR
RAHUL PATIDAR - avatar
2 Answers
+ 12
Variables are called so because they are subjected to change during program flow. This is the most basic and essential building block of your programs. E.g. int sum = 0; int num = 1; int i = 0; while (i < 5) { sum += num; i++; } In the above section of a program you can see that variable sum and variable i both change values for each loop iteration, respectively for their specific purposes. The examples in the slides are just to show you how variables are altered.
26th Feb 2017, 8:21 AM
Hatsy Rei
Hatsy Rei - avatar
+ 3
variables are for values that tend to change like when you log into a site it says welcome username with username being the variable
26th Feb 2017, 8:31 AM
Andre van Rensburg
Andre van Rensburg - avatar