Character Array MCQ 14 : Printing String in Function Recursively

   

Character Array MCQ 14 : Printing String Recursively


What is the Output of the Following Program ?

#include<stdio.h>
int main()
{
int i=0;
printf("\nI am in Main");
for(i=0;i<10;i++)
   main();
return(0);
}

Options :
[arrowlist]

  • 1.I am in MainI am in Main—- Infinite Times
  • 2.I am in MainI am in Main—- 10 Times
  • 3.I am in MainI am in Main—- Until Internal Stack Overflows
  • 4.None Of These
[/arrowlist] Output:


Switch to String MCQ Home : Click Here


Note:
  • Function Does Not Remember Values Initialized Inside Calling Function except Static Variable.
  • So After Printing Message , again main() Function gets Called Where again i becomes 0
  • Thus This Program Runs Forever , Theoretically This Program Prints Message Infinite Number of Times
  • While Calling Recursive Function Contents are Pushed onto Internal Stack When This Internal Stack Overflows Program stops
  • We can Terminate Program Execution by Pressing Ctrl+Pause/Break