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- A. 3 2
- B. 4 1
- C. 3 1
- 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.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- What will be the output of the following pseudocode? (& is AND, | is OR, << and >> are shifts) Integer x = 43 Integer y = ((x & 170) >> 1)…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division; & is AND, ^ is XOR, | is OR…
- What will be the output of the following pseudocode? Integer n = 3524, steps = 0 while (n != 6174) Integer big = digits of n sorted in…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division) Integer total = 0, n for (each…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division; + joins strings) Function…
- What will be the output of the following pseudocode? Integer m[3][3] = {{1, 2, 3}, {2, 5, 9}, {4, 6, 0}} Integer bad = 0 for (each i from…