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 |
hi , please send me NIC written test papers to sbabavalli@gmail.com
Explain about the constants which help in debugging?
Why does not use getgh(); and <conio.h> in c language.
write a program without using main function?
What is the difference between ++a and a++?
Describe the header file and its usage in c programming?
6. Which of the Following is not defined in string.h? A)strspn() B)strerror() C)memchr() D)strod()
how to count no of words,characters,lines in a paragraph.
what is answer for perfect number????????????????
How to write a code for random pick from 1-1000 numbers? The output should contain the 10 numbers from the range 1-1000 which should pick randomly, ie ,for each time we run the code we should get different outputs.
process by which one bit patten in to another by bit wise operation is? (a) masking, (b) pruning, (c) biting, (d) chopping,
how to impliment 2 or more stacks in a single dimensional array ?