33. What will be the output of following code :
// Assume all header files are included
main()
{
static int var = 5;
printf("%d ",var--);
if(var)
main();
}
A. 1 3 2 5 8
B. 5 4 3 2 1
C. 5 8 9 6 4
D. Runtime Error
View Answer & Explanation
Ans. b
Explanation : When static storage class is given, it is initialized once. The change 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.
34. What will be the output of following code :
// Assume all header files are included
main()
{
extern int i;
i=20;
printf("%d",i);
}
A. 20
B. Linker Error : Undefined symbol ‘_i
C. 19
D. Runtime Error
View Answer & Explanation
Ans. b
Explanation : extern int i; specifies to the compiler that the memory for i is allocated in some other program and thataddress will be given to the current program at the time of linking
