Programming Basics (Pseudocode Tracing)
The following program passes values along three variables. What are the values of a, b and c after it runs?
integer: a ← 1, b ← 2, c ← 3, t
t ← a
a ← b
b ← c
c ← t
- Aa = 2, b = 3, c = 1
- Ba = 2, b = 3, c = 2
- Ca = 3, b = 1, c = 2
Show answer and explanation
Answer: A. a = 2, b = 3, c = 1
t ← a saves the original value of a, 1, in t. a ← b makes a = 2, b ← c makes b = 3, and the final c ← t puts the saved 1 into c. The three values each move one place forward, giving a = 2, b = 3, c = 1. Writing c ← a without t would give c = 2, because a has already become 2 by then.
- A. Correct. The saved original value of a, 1, ends up in c.
- B. This is the result of writing c ← a instead of c ← t. By then a has already changed to 2.
- C. This rotates the values the other way. Because the order is a ← b, b ← c, the values move forward.
Continue: 9 more Programming Basics (Pseudocode Tracing) questions