ProgrammingVery hardAccenture · Capgemini

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
Integer x = 0, i
for (i = 1; i <= 10; i = i + 1)
    x = ((x << 1) ^ i) & 15
end for
Print x
(<< is left shift, ^ is XOR, & is AND.)
  1. A. 0
  2. B. 1
  3. C. 5
  4. D. 6

Correct answer: A. 0

x after each iteration (kept to 4 bits): 1, 0, 3, 2, 1, 4, 15, 6, 5, 0, so the final value is 0.

More Pseudocode and Code Tracing questions

Exams that ask this topic