?
Determine Output:
Determine Output:
void main()
{
static int i=5;
if(--i){
main();
printf("%d ", i);
}
}
void main()
{
static int i=5;
if(--i){
main();
printf("%d ", i);
}
}
Answer & Solution
Correct Answer:
Option
B
The variable "i" is declared as static, hence memory for I will be allocated for only once, as it encounters the statement. The function main() will be called recursively unless I becomes equal to 0, and since main() is recursively called, so the value of static I ie., 0 will be printed every time the control is returned.
Join the Discussion
Login to post a comment or share your explanation.
Loginmain() is called recursively.
i is decremented to 4, and main() is called recursively.
i is decremented to 3, and main() is called recursively.
i is decremented to 2, and main() is called recursively.
i is decremented to 1, and main() is called recursively.
i is decremented to 0, and main() is called recursively.
i is printed (0).
Control goes back to the previous recursive call. i is printed (1).
Control goes back to the previous recursive call. i is printed (2).
Control goes back to the previous recursive call. i is printed (3).
Control goes back to the previous recursive call. i is printed (4).
Therefore, the output of the program will be 0000.
souravkumarnanda@gmail.com