ProgrammingHardInfosys SP · Capgemini
What will be the output of the following pseudocode? (integers are 32-bit; & is AND, << and >> are shifts)
What will be the output of the following pseudocode? (integers are 32-bit; & is AND, << and >> are shifts)
Integer x = 45 Integer y = (x << 3) & 255 Integer z = (x << 3) >> 3 Print y, z
- A. 360 45
- B. 104 13
- C. 104 45
- D. 45 45
Correct answer: C. 104 45
45 << 3 = 360. Keeping only the low 8 bits: 360 − 256 = 104. Without that mask the value is not cut, so shifting back gives 45 again: 104 45.
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? // BST: smaller keys go left, larger (or equal) keys go right Insert into an empty…
- What will be the output of the following pseudocode? Insert into an empty BST, in this order: 8, 3, 10, 1, 6, 14, 4, 7, 13 Queue q =…
- What will be the output of the following pseudocode? (Print writes its values on one line, separated by spaces) Integer burst[3] = {5, 3…
- What will be the output of the following pseudocode? Integer g[4][4] = {{0,0,0,0}, {0,1,0,0}, {0,0,0,1}, {1,0,0,0}} // 1 = blocked Integer…
- What will be the output of the following pseudocode? (substring(s, i, len) is len characters starting at index i; a Set keeps one copy of…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division; strings are indexed from 0)…