Consider the following two functions. The output printed when fun1(5) is…
2017
Consider the following two functions.

The output printed when fun1(5) is called is
- A.
53423122233445
- B.
53423120112233
- C.
53423122132435
- D.
53423120213243
Attempted by 54 students.
Show answer & explanation
Correct answer: A
Key idea: trace the mutual recursion and remember that ++n in the second function increments n before the recursive call, affecting subsequent prints.
fun1(5) prints 5
fun2(3) prints 3
fun2 increments n to 4 and calls fun1(4); fun1(4) prints 4
fun2(2) prints 2
fun2 increments to 3 and calls fun1(3); fun1(3) prints 3
fun2(1) prints 1
fun2 increments to 2 and calls fun1(2); fun1(2) prints 2
fun1(2) calls fun2(0) which returns immediately, then fun1(2) prints 2 (second time)
Return to fun2(1): it now prints its n (which was incremented to 2), producing another 2
Return to fun1(3): it prints 3
Return to fun2(2): it prints its n (which is 3)
Return to fun1(4): it prints 4
Return to fun2(3): it prints its n (which is 4)
Return to fun1(5): it prints 5
Final output: 53423122233445
A video solution is available for this question — log in and enroll to watch it.