ProgrammingEasyTCS NQT · Wipro pattern

What will be the output of the following pseudocode? (/ is integer division.)

What will be the output of the following pseudocode? (/ is integer division.)
Integer x = 10
x = x + x * 2 - 4 / 2
Print x
  1. A. 18
  2. B. 38
  3. C. 20
  4. D. 28

Correct answer: D. 28

* and / first: x * 2 = 20 and 4 / 2 = 2. Then left to right: 10 + 20 − 2 = 28. Evaluating strictly left to right ((10 + 10) * 2 − 4) / 2 = 18 ignores precedence.

More Pseudocode and Code Tracing questions

Exams that ask this topic