ProgrammingModerateTCS NQT · Accenture pattern

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
Integer x = 5, y = 9
x = x ^ y         // ^ is bitwise XOR
y = x ^ y
x = x ^ y
Print x, y, (5 & 9), (5 | 9)
  1. A. 9 5 1 13
  2. B. 9 5 0 14
  3. C. 5 9 1 13
  4. D. 9 5 1 14

Correct answer: A. 9 5 1 13

Three XORs swap the values: x = 9, y = 5. 5 = 0101 and 9 = 1001 share only bit 0, so 5 & 9 = 1 and 5 | 9 = 1101 = 13 (5 ^ 9 would be 12).

More Pseudocode and Code Tracing questions

Exams that ask this topic