C Quiz – 106 | Question 1

Assuming int size is 4 bytes, what is going to happen when we compile and run the following program?





#include “stdio.h”
int main()
  return 0;


(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.

Answer: (E)

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

GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details

My Personal Notes arrow_drop_up
Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.