ProgrammingModerateAccenture · Cognizant pattern

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
Integer x = 7, y = 3
Print x mod y * y + x / y
  1. A. 5
  2. B. 3
  3. C. 8
  4. D. 9

Correct answer: A. 5

mod, * and / share the same precedence and are worked left to right: (7 mod 3) × 3 = 3, then 7 / 3 = 2 with integer division, so 3 + 2 = 5. Reading it as 7 mod (3 × 3) gives 7 + 2 = 9.

More Pseudocode and Code Tracing questions

Exams that ask this topic