ProgrammingModerateInfosys SP · TCS NQT
What will be the output of the following pseudocode? (| is OR, & is AND, << and >> are shifts)
What will be the output of the following pseudocode? (| is OR, & is AND, << and >> are shifts)
Integer x = 1, r = 0
for (each i from 1 to 8)
r = (r << 1) | (x & 1)
x = x >> 1
end for
Print r- A. 128
- B. 1
- C. 256
- D. 2
Correct answer: A. 128
The loop reverses the lowest 8 bits: 00000001 becomes 10000000 = 128.
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 m[3][3] = {{2, 0, 1}, {1, 3, 2}, {1, 1, 1}} Integer det = m[0][0] (m[1][1]…
- What will be the output of the following pseudocode? Integer m[4][4] = {{4, 3, 2, -1}, {3, 2, 1, -1}, {1, 1, -1, -2}, {-1, -1, -2, -3}}…
- What will be the output of the following pseudocode? // list: 1 -> 2 -> 3 -> 4 -> 5 -> NULL Integer n = 5, k = 2 Node tail = last node…
- What will be the output of the following pseudocode? Insert into an empty BST, in this order: 50, 30, 70, 20, 40, 60, 80, 35, 45, 65…
- What will be the output of the following pseudocode? // undirected graph; neighbours are visited in increasing order Edges: 1-2, 1-3, 2-4…
- What will be the output of the following pseudocode? // undirected graph; neighbours are visited in increasing order Edges: 1-2, 1-3, 2-4…