void main()
{
static int i = 5;
if(--i)
{
main();
printf("%d
",i);
}
}
what would be output of the above program and justify your
answer?
}
Answers were Sorted based on User's Feedback
Answer / 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 |
Answer / srsabariselvan
0
0
0
0
static variable's value is stored in memory statically upto
end of the program. so if the variable comes out of the
function it retains its value
| Is This Answer Correct ? | 13 Yes | 5 No |
Answer / sri ram
This prog'll not produce any output since the value of i
reduces when it reaches zero if block will not be executed
and the program is terminated....
| Is This Answer Correct ? | 7 Yes | 16 No |
how many types of operators are include in c language a) 4 b) 6 c) 8 d) 12
What is array of pointers to string?
int zap(int n) { if(n<=1)then zap=1; else zap=zap(n-3)+zap(n-1); } then the call zap(6) gives the values of zap [a] 8 [b] 9 [c] 6 [d] 12 [e] 15
How do you write a program which produces its own source code as output?
hi how to convert program from notepad to turboc editor can u please help me
Write a program that takes three variables(a,b,c) in as separate parameters and rotates the values stored so that value a goes to b,b,to c and c to a
the maximum length of a character constant can be a) 1 character b) 8 characters c) 256 chaacters d) 125 characters
WRITE A CODE IN C TO SEARCH A FILE FROM NOTEPAD FILE.
What are the types of i/o functions?
wat are the two methods for swapping two numbers without using temp variable??
Write a program to print distinct words in an input along with their count in input in decreasing order of their count..
Why is void main used?