ProgrammingModerateInfosys SP · TCS NQT

What will be the output of the following pseudocode? (& is AND, >> is right shift)

What will be the output of the following pseudocode? (& is AND, >> is right shift)
Integer x = 23, t = 0
while ((x & 1) == 1)
    t = t + 1
    x = x >> 1
end while
Print t, x
  1. A. 3 2
  2. B. 4 1
  3. C. 3 1
  4. D. 1 11

Correct answer: A. 3 2

23 = 10111 in binary: three 1's at the right end. After removing them x = 10 in binary = 2: 3 2.

More Pseudocode and Code Tracing questions

Exams that ask this topic