ProgrammingModerateTCS NQT · Accenture

What will be the output of the following pseudocode? (All variables are integers, so / is integer division; , / and mod have equal precedence)

What will be the output of the following pseudocode? (All variables are integers, so / is integer division; *, / and mod have equal precedence)
Integer a = 7, b = 3, c = 2
Print a - b * c / 4 + a mod b * c
  1. A. 8
  2. B. 0
  3. C. 9
  4. D. 7.5

Correct answer: A. 8

*, / and mod share one level and go left to right: b * c / 4 = 6 / 4 = 1 and a mod b * c = 1 * 2 = 2, so 7 − 1 + 2 = 8. Doing c / 4 first gives 9, real division gives 7.5, and ignoring precedence entirely, ((((a − b) * c) / 4 + a) mod b) * c, gives 0.

More Pseudocode and Code Tracing questions

Exams that ask this topic