void main()
{
static int i = 5;
if(--i)
{
main();
printf("%d
",i);
}
}
what would be output of the above program and justify your
answer?
}
Answer Posted / samrat
Ans: 0 0 0 0
The first thing you have to remember is that static
variables are initialized only once. The second thing is
that static variables have a life time scope and they retain
their value between function calls.
"i" is first initialized to 5. in the if condition the value
of i is changed to 4. main() is called again and the value
of i is changed to 3 in the if condition and main is called
again. Now the value of i is changed to 2 and main is called
again. Now the value of i is changed to 1 and main is called
again. After this the value of i is changed to "0" and the
block is excited.
As the value of i is now "0", it is printed 4 times for each
of the calls for main(). So the ans will be
0
0
0
0
Thanks,
Samrat
Is This Answer Correct ? | 67 Yes | 5 No |
Post New Answer View All Answers
What will be the outcome of the following conditional statement if the value of variable s is 10?
What is scanf () in c?
Explain the difference between malloc() and calloc() in c?
How will you declare an array of three function pointers where each function receives two ints and returns a float?
What is c language & why it is used?
What are the 5 elements of structure?
What is array in c with example?
Why c is called free form language?
a=10;b= 5;c=3;d=3; if(a printf(%d %d %d %d a,b,c,d) else printf("%d %d %d %d a,b,c,d);
Explain what are bus errors, memory faults, and core dumps?
Why is not a pointer null after calling free? How unsafe is it to use (assign, compare) a pointer value after it is been freed?
What is the use of a conditional inclusion statement in C?
How to Throw some light on the splay trees?
A global variable when referred to in another file is declared as this a) local variable b) external variable c) constant d) pointers
I completed my B.tech (IT). Actually I want to develop virtual object that which will change software technology in the future. To develop virtual object what course I have to take. can I any professor to help me.