edited by
372 views
1 votes
1 votes

 

#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 _________.

edited by

1 Answer

Best answer
2 votes
2 votes
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
Answer:

Related questions

0 votes
0 votes
1 answer
1
Bikram asked May 14, 2017
351 views
Spot the error(s) in this code snippet :int n=2; // Line 1 switch(n) { case 1.5: printf( "gate"); break; case 2: printf( "overflow"); break; case 'A': printf("gateoverflo...
0 votes
0 votes
0 answers
2
Bikram asked May 14, 2017
196 views
#include <stdio.h int counter(int i) { static int count = 0; count = count + i; return count; } int main() { int i, j; for (i = 0; i <= 5; i++) j = counter(i); printf ("%...
1 votes
1 votes
1 answer
3
Bikram asked May 14, 2017
291 views
What is the output of the following program?#include <stdio.h int main() { int a = 0; switch(a) { default: a = 4; case 6: a ; case 5: a = a+1; case 1: a = a-1; } printf("...
7 votes
7 votes
2 answers
4
Bikram asked May 14, 2017
538 views
What is the output of the following code snippet? #include <stdio.h int main() { char c=125; c=c+10; printf("%d",c); return 0; }