in Programming edited by
223 views
1 vote
1 vote

 

#include <stdio.h>
void fun()
{
    int p;
    static int x=1;
    p = ++x;
    printf("%d %d", p, x);
    if(p <= 2)
        fun();
    printf(ā€œ%d %dā€, p, x);
}
int main()
{
    fun();
    fun();
}

In the above code fragment, the total number of times printf statement will be executed is _________.

in Programming edited by
by
223 views

3 Comments

The question in the test is wrong. It doesn't have #include <stdio.h> but simply #include void fun...

This will result in the compile error. 

0
0
@vasu

okay , i understand..it is spacing problem , in actual question after #include , header file is there ..

i will fix that .. if possible you can answer here as you can see correct code here.
0
0

Vasu Srivastava  

I corrected this kind of issue, can you plz tell me in exam interface how it  looks like  now ?

0
0

1 Answer

2 votes
2 votes
Best answer
number of printf statement->6 times

output will be=

 2 2

3 3

3 3

2 3

4 4

4 4

when we call fun() it will call printf twice ,here in main

1st fun()  calling   fun() again

and after that

2nd fun() of main

therefore fun is called 3 times , printf get executed 6 times
selected by

3 Comments

plz explain 4th step how 2,3 is printed
0
0
@Deependra Sir

main()---->fun()[p=1 then 2 -------fun()[[[[[[p=3    printf();     p<=2(false)       printf()](scope of inner function end here and local copy of p also deleted]]]]]]]   in 1st fun we left with one printf()  (it take local value of this i.e 2)]  therefore 2 3 printed
0
0
Got it thanx
0
0
Answer:

Related questions