What is the output of the following program?
main()
in the value of a static variable is retained even between the function calls. Main
is also treated like any other ordinary function, which can be called recursively.
main()
{
static
int var = 5;
printf("%d ",var--);
if(var)
printf("%d ",var--);
if(var)
main();
}
Answer:
5 4 3 2 1
Explanation:
When static storage class is given, it is initialized once. The changein the value of a static variable is retained even between the function calls. Main
is also treated like any other ordinary function, which can be called recursively.
No comments:
Post a Comment