ProgrammingModerateInfosys · Cognizant pattern
What will be the output of the following pseudocode? (Byte variables are 8-bit unsigned: they hold 0–255 and arithmetic wraps modulo 256.)
What will be the output of the following pseudocode? (Byte variables are 8-bit unsigned: they hold 0–255 and arithmetic wraps modulo 256.)
Byte x = 200, y = 100, z, w, d z = x + y w = x * 2 d = y - x Print z, w, d
- A. 300 400 -100
- B. 44 144 156
- C. 44 144 100
- D. 255 255 0
Correct answer: B. 44 144 156
Results are reduced modulo 256: 300 − 256 = 44, 400 − 256 = 144, and −100 + 256 = 156. Unsigned types wrap rather than saturate, so '255 255 0' is wrong, and a negative value cannot be stored at all.
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? (Strings are indexed from 0; swap exchanges two characters.) String s = "ABCDEF"…
- What will be the output of the following pseudocode? Integer c = 0 for (i = 1 to 5) for (j = i to 5) if ((i + j) mod 3 == 0) c = c + 1 end…
- What will be the output of the following pseudocode? (/ is integer division; calls counts every call of f.) Integer calls = 0 Function…
- What will be the output of the following pseudocode? (Arrays are indexed from 0.) Integer a[5] = {1, 2, 3, 4, 5}, t for (i = 0 to 4) t =…
- What will be the output of the following pseudocode? (Arrays are indexed from 0.) Integer a[5] = {5, 1, 8, 2, 3}, c = 0 for (i = 0 to 3)…
- What will be the output of the following pseudocode? (A static variable is initialised once and keeps its value between calls; operands…