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
  1. A. 300 400 -100
  2. B. 44 144 156
  3. C. 44 144 100
  4. 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.

More Pseudocode and Code Tracing questions

Exams that ask this topic