C Quiz – 106 | Question 1
Assuming int size is 4 bytes, what is going to happen when we compile and run the following program?
(A) We can’t use main() inside main() and compiler will catch it by showing compiler error.
(B) GeeksQuiz would be printed in 2147483647 times i.e. (2 to the power 31) – 1.
(C) It’ll print GeeksQuiz infinite times i.e. the program will continue to run forever until it’s terminated by other means such as CTRL+C or CTRL+Z etc.
(D) GeeksQuiz would be printed only once. Because when main() is used inside main(), it’s ignored by compiler at run time. This is to make sure that main() is called only once.
(E) GeeksQuiz would be printed until stack overflow happens for this program.
Explanation: First of all, there’s no restriction of main() calling main() i.e. recursion can happen for main() as well. But there’s no explicit termination condition mentioned here for this recursion. So main() would be calling main() after printing GeeksQuiz. This will go on until Stack of the program would be filled completely. Please note that stack (internal to a running program) stores the calling function sequence i.e. which function has called which function so that the control can be returned when called function returns. That’s why here in program, main() would continue to call main() until complete stack is over i.e. stack-overflow occurs.
Quiz of this Question