AP CSP Day 23: Agile Methods
Share
Practice Question
What is displayed after the following code runs?
a ← 3
b ← 7
a ← a + b
b ← a - b
DISPLAY(a)
DISPLAY(b)Starting: a=3, b=7. After a ← a + b: a = 3+7 = 10. After b ← a - b: b = 10-7 = 3 (using the current value of a, which is now 10). Display shows 10 then 3.
A) Students who pick this use the current a (10) correctly for the first display but forget to update b. B is correct because b changes too. C) Both variables are modified by the code. B) This reverses the displayed order or uses wrong intermediate values.
Students use the original value of a (3) instead of the updated value (10) when computing b ← a - b. Always use the most recent value of a variable.
When a variable appears on both sides of an assignment, the right side is evaluated first using current values, then the result is stored on the left. Update your trace immediately.
Keep Practicing!
Consistent daily practice is the key to AP CSP success.
AP CSP Resources Get 1-on-1 Help