Friday, 30 March 2012

Aptitude- Predict the output

void main() {
static int i=5;
if(--i)
{
main();
printf("%d ",i);
}
}
Ans: c 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