Nov 6, 2010

Find the output.

void main()
{
static int i=5;
if(--i)
{
main();
printf("%d ",i);
}
}


Output: 
0 0 0 0


Explanation:
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.

No comments:

Post a Comment