49. What will be the output of following code :
// Assume all header files are included
void main()
{
static int i=5;
if(--i){
main();
printf("%d ",i);
}
}
A. 0 0 0
B. 0 0 0 0
C.0 0
D. Runtime Error
View Answer & Explanation
Ans. b
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.
50. What will be the output of following code :
// Assume all header files are included
void main()
{
int i;
char a[]="\0";
if(printf("%s\n",a))
printf("Ok here \n");
else
printf("Forget it\n");
}
A. OK here
B. Ok here
C. Forget it
D. Runtime Error
View Answer & Explanation
Ans. b
Explanation : Printf will return how many characters does it print. Hence printing a
null character returns 1 which makes the if statement true, thus “Ok
here” is printed.
