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
  1. Aa = 2, b = 3, c = 1
  2. Ba = 2, b = 3, c = 2
  3. 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.
Practice this topic Back to topic

Related calculators

Books on Programming Basics (Pseudocode Tracing) Ad

As an Amazon Associate I earn from qualifying purchases.

More Programming Basics (Pseudocode Tracing) questions

  1. The following program repeatedly multiplies x by 3. What is the value of n after it runs?
  2. The following for loop increases i by 2. What is the value of s after it runs?
  3. In the following nested loop, the inner loop starts from the outer variable i. What is the value of c after it runs?
  4. The following program has a condition inside a nested loop. What is the value of c after it runs?
  5. The following program was meant to compute the sum of all elements of array a. Array indices start at 1. What is the value of s after it runs?