Watch the Order of Updates
Trace two variables and explain how assignment order changes the result.
Supplied materials
- Paper and pencil; an adult may read aloud. No device, account or purchase is needed.
Learn the idea
A variable name refers to its current value. An assignment such as b = a copies a’s value at that moment; it does not make b follow every later change to a. Execute statements from top to bottom and write both variables after each statement, even when only one changes.
Paper program: set a = 2; set b = 0; set b = a; set a = a + 3; show a and b. The copy happens before the addition. We will compare it with a modified program that adds to a before copying a into b. The statements use the same numbers but their order changes b.
- Draw columns statement, a and b; use a dash before a variable is set.
- Trace a = 2 and b = 0.
- Copy a into b, then add 3 to a and record both values.
- Swap the last two updates and trace again from the start.
See the method in action
Original rows after both variables are set: (a, b) = (2, 0) → (2, 2) → (5, 2). Reordered updates give (2, 0) → (5, 0) → (5, 5). The original shows 5 and 2.
Check your reasoning
Your answer is temporary and is not saved to an account. Download your current answer before leaving or reloading. Written work on paper or in another app stays in your own file.
See the answer and explanation
a = 5, b = 4
b copies the current 4 before a increases to 5. It remains 4 afterward.
Take it further
In the original program, change the start to a = 6. Expected original output: a = 9, b = 6. If you add first and copy second, both are 9.
Nothing here is saved to an account or sent to a teacher. The answer download includes your current choice and any checked feedback.
Check the subject sources
These LifeStarter passages, scenarios and exercises are authored for this Academy with AI assistance and review. External resources keep their publishers’ terms. A grade label suggests a starting level; it does not establish alignment with your school’s complete requirements.