ProgrammingHardInfosys SP · Amazon OA
What will be the output of the following pseudocode? (<< is left shift, | is bitwise OR, & is bitwise AND)
What will be the output of the following pseudocode? (<< is left shift, | is bitwise OR, & is bitwise AND)
Integer x = 0
for (each i from 0 to 4)
x = (x << 2) | (i & 3)
end for
Print x- A. 108
- B. 228
- C. 27
- D. 120
Correct answer: A. 108
Each step appends two bits, i.e. one base-4 digit i & 3: the digits are 0, 1, 2, 3, 0. So x = 01230 in base 4 = 64 + 32 + 12 + 0 = 108.
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 mults = 0 Function…
- What will be the output of the following pseudocode? String s = "(()(()))()" Integer depth = 0, best = 0, pairs = 0 for (each i from 0 to…
- What will be the output of the following pseudocode? (^ is XOR, & is AND) Integer s = 0, x, p for (each i from 1 to 20) x = i p = 0 while…
- What will be the output of the following pseudocode? Integer P[4][4] = all 0 Integer A[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}} for (each…
- 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? // BST: smaller keys go to the left, larger to the right Insert into an empty BST, in…