edited by
20,117 views
47 votes
47 votes

Consider the following two functions.

void fun1(int n) {
    if(n == 0) return;
    printf("%d", n);
    fun2(n - 2);
    printf("%d", n);
}
void fun2(int n) {
    if(n == 0) return;
    printf("%d", n);
    fun1(++n);
    printf("%d", n);
}

The output printed when $\text{fun1}(5)$ is called is

  1. $53423122233445$  
  2. $53423120112233$                       
  3. $53423122132435$  
  4. $53423120213243$                       
edited by

11 Answers

Best answer
98 votes
98 votes

  • Unroll recursion up to a point where we can distinguish the given options and choose the correct one!
  • Options B and D are eliminated.
  • A is the answer.
edited by
54 votes
54 votes

hence correct answer is a.

11 votes
11 votes

ANS)A

In fun2,value of n also get incremented after each function call.

Answer:

Related questions

68 votes
68 votes
5 answers
4