ProgrammingModerateAmazon OA · TCS NQT

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
Integer a[7] = {4, 1, 2, 1, 2, 5, 4}
Integer x = 0
for (each i from 0 to 6)
    x = x ^ a[i]
end for
Print x
  1. A. 19
  2. B. 5
  3. C. 0
  4. D. 4

Correct answer: B. 5

XOR cancels equal pairs (v ^ v = 0) and is order-free, so the pairs 4, 1, 2 vanish and the single unpaired 5 remains.

More Pseudocode and Code Tracing questions

Exams that ask this topic