Right Click to Search

Saturday, August 21, 2024

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 :
  1. I am in Main
    I am in Main
    I am in Main
    -----------
    -----------
    ----------- Infinite Times
  2. I am in Main
    I am in Main
    I am in Main
    -----------
    -----------
    ----------- 10 Times
  3. I am in Main
    I am in Main
    I am in Main
    -----------
    -----------
    ----------- Until Internal Stack Overflows
    
  4. None Of These


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

Tags / Keywords : |

Stumble
Delicious
Technorati
Twitter
Facebook

0 Comments:

Post a Comment

Your Feedback :This is Growing Site and Your Feedback is important for Us to improve the Site performance & Quality of Content.Feel Free to contact and Please Provide Name & Contact Email

 

Learn C Programming Copyright © 2010 LKart Theme is Designed by Lasantha, Free Blogger Templates