Skip to main content
Logo image

Section 4.4 Modifying Variables

After declaring and initializing a variable, the stored value is not set in stone. It can be updated!
Next, we’ll learn how to modify the value of a variable in a program.

If you cannot see this codecast, please click here.

Check Your Understanding Check Your Understanding

1.

Suppose you declare and initialize a variable at the beginning of your program as follows:
int var;
var = 10;
What is the value of the variable var after the line
var = var + 20;
has been executed?

2.

Continuing from the question above, your program now contains the next line:
var = var - 5;
What is the value of var after this statement?

3.

Finally, your program contains the two lines:
var = 100;
var = var+50;
What is the value of var after these two lines have been executed?