AP CSP Day 53: Data Storage
Share
Practice Question
What is displayed after the following code runs?
a ← 1
b ← 2
c ← 3
a ← b + c
b ← a + c
c ← a + b
DISPLAY(c)Trace each assignment using current values: a = b+c = 2+3 = 5. Then b = a+c = 5+3 = 8 (using updated a). Then c = a+b = 5+8 = 13 (using updated a and b). DISPLAY shows 13.
A) 6 uses original values (1+2+3). Students who don't update variables get this wrong answer. C) 8 is the value of b, not c. D) 16 results from arithmetic errors in the trace.
Students use the original values (a=1, b=2, c=3) throughout all three computations instead of using the updated value of each variable as soon as it changes.
In multi-step assignment problems, update your variable table immediately after each assignment. The next line must use the new values, not the originals.
Keep Practicing!
Consistent daily practice is the key to AP CSP success.
AP CSP Resources Get 1-on-1 Help