Variables and Assignments MCQ Practice

Question 1 of 10

What is displayed?

k ← 12
k ← 5
DISPLAY (k)
  1. A. Nothing is displayed.
  2. B. 12
  3. C. 5
  4. D. 17

Question 2 of 10

Which description matches the effect of w ← z when w is 4 and z is 9 beforehand?

  1. A. w stays 4 and z becomes 4
  2. B. Both become 13
  3. C. w becomes 9 and z becomes 4
  4. D. w becomes 9 and z stays 9

Question 3 of 10

A botched swap runs as follows with u = 1 and v = 2 initially.

u ← v
v ← u

What are u and v afterward?

  1. A. u is 2 and v is 2
  2. B. u is 1 and v is 1
  3. C. u is 1 and v is 2
  4. D. u is 2 and v is 1

Question 4 of 10

After the segment, which values are stored?

p ← 4
q ← 9
r ← p
p ← q
q ← r
  1. A. p is 4, q is 9, r is 4
  2. B. p is 9, q is 4, r is 4
  3. C. p is 9, q is 9, r is 4
  4. D. p is 4, q is 4, r is 9

Question 5 of 10

A variable can best be described as:

  1. A. A list that always stores exactly two values.
  2. B. A permanent label that can never change its associated value.
  3. C. A named storage location that holds one value at a time, which can be updated by assignment.
  4. D. A DISPLAY command that prints text.

Question 6 of 10

Trace carefully. What is displayed in order?

a ← 5
b ← 2
a ← a - b
b ← a + b
a ← b - a
DISPLAY (a)
DISPLAY (b)
  1. A. 5 then 2
  2. B. 3 then 5
  3. C. 3 then 3
  4. D. 2 then 5

Question 7 of 10

The order of assignments matters. Which final value of t is produced?

t ← 10
t ← t / 2
t ← t + 3
  1. A. 8
  2. B. 13
  3. C. 5
  4. D. 16

Question 8 of 10

Which segment ends with high and low swapped from their initial values high=20 and low=5?

  1. A. high ← low then low ← high
  2. B. temp ← high then high ← low then low ← temp
  3. C. high ← high - low then low ← high
  4. D. low ← low then high ← high

Question 9 of 10

After count ← 0 and then three statements count ← count + 1, what is count?

  1. A. 1
  2. B. 2
  3. C. 3
  4. D. 0

Question 10 of 10

A program runs:

x ← 2
y ← x
x ← 9
DISPLAY (y)

What is displayed, and why?

  1. A. 11, because y stores x + 9
  2. B. Nothing, because y was never assigned
  3. C. 9, because y is an alias that always mirrors x
  4. D. 2, because y received a copy of the value of x at the time of assignment