in Programming in C edited by
20,210 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$                       
in Programming in C edited by
by
20.2k views

4 Comments

Whenever we take a static variable, until function calls are over we won't print the value i.e. we take the last updated value after the function call and then we print it,but if the variable is global then why do we directly take the value and print it .​​?Here second printf stmt i.e.stmt after function call we fixed the value into the variable and it's been printed at the end.why? 

0
0
Yeah got it bro.And the video is primarily focussed on how to use options to get the correct solution
0
0
Mistakes we might do in the question are like not considering pre-increment.
0
0

11 Answers

98 votes
98 votes
Best answer

  • 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
by

4 Comments

means?
0
0
please anyone can tell me that why right side printf value is incremented
0
0
pre-increment and for every function call there’ll be activation record which will store the local variable values .So, at the time of fun call ,variable value has been incremented .It was stored and that’s the reason why it has been incremented.
1
1
54 votes
54 votes

hence correct answer is a.

4 Comments

Thank you :)
0
0
please anyone can tell me that why right side printf value is incremented
0
0

in $f_2()$ after the printf statement there is a pre-increment of variable $n$.

1
1
11 votes
11 votes

ANS)A

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

1 comment

please anyone can tell me that why right side printf value is incremented
0
0
8 votes
8 votes

\

Solution......

1 comment

please anyone can tell me that why right side printf value is incremented
0
0
Answer:

Related questions