ProgrammingModerateTCS NQT · Wipro

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
Function f(Integer a, Integer b)
    return a * b - (a + b)
End Function
Print f(f(2, 3), f(1, 4))
  1. A. -3
  2. B. -1
  3. C. 0
  4. D. 5

Correct answer: B. -1

Inner calls first: f(2, 3) = 6 − 5 = 1 and f(1, 4) = 4 − 5 = −1. Then f(1, −1) = (1)(−1) − (1 + (−1)) = −1 − 0 = −1.

More Pseudocode and Code Tracing questions

Exams that ask this topic