ProgrammingHardTCS NQT · Accenture pattern
What will be the output of the following pseudocode? (& is bitwise AND, | is bitwise OR, ^ is bitwise XOR, << and >> are left and right shifts.)
What will be the output of the following pseudocode? (& is bitwise AND, | is bitwise OR, ^ is bitwise XOR, << and >> are left and right shifts.)
Integer n = 1, c = 0
while (n < 200)
n = n << 1
c = c + 1
end while
Print c, n- A. 8 128
- B. 7 128
- C. 8 256
- D. 9 512
Correct answer: C. 8 256
Each shift doubles n: 2, 4, 8, ..., 128, 256. The test 128 < 200 still passes, so the eighth shift makes n = 256 and then the loop stops.
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? Integer c = 0 for (each i from 1 to 5) for (each j from 1 to 5) if (j > i) break end…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division.) Integer n = 2048, c = 0, d…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division.) Function f(Integer n) if (n…
- What will be the output of the following pseudocode? Integer s = 0 for (each i from 1 to 3) for (each j from 1 to 3) if (i == j) continue…
- What will be the output of the following pseudocode? (& is bitwise AND, | is bitwise OR, ^ is bitwise XOR, << and >> are left and right…
- What will be the output of the following pseudocode? (Arrays are indexed from 0.) Integer arr[5] = {1, 2, 3, 4, 5} Integer t for (each k…