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 = 40, pos = 1
while ((x & 1) == 0)
x = x >> 1
pos = pos + 1
end while
Integer n = 1000, bits = 0
while (n > 0)
bits = bits + 1
n = n >> 1
end while
Print pos, bits- A. 3 9
- B. 4 9
- C. 3 10
- D. 4 10
Correct answer: D. 4 10
40 = 101000, so its lowest 1-bit is the 4th from the right: pos = 4. 1000 lies between 2⁹ = 512 and 2¹⁰ = 1024, so it needs 10 bits. Output 4 10.
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? (All variables are integers, so / is integer division) Integer n = 10, steps = 0…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division; and / are evaluated left to…
- What will be the output of the following pseudocode? Integer h[6] = {2, 1, 5, 6, 2, 3}, best = 0 for (each i from 0 to 5) Integer mn =…
- What will be the output of the following pseudocode? String stream = "aabcbc" Integer cnt[26] = all 0 Queue q = empty for (each ch in…
- What will be the output of the following pseudocode? Procedure f(Integer n) if (n == 0) return end if Print n f(n - 1) Print n End…
- What will be the output of the following pseudocode? // a trie (prefix tree) starts with only an empty root for each word in {"car"…