Possible duplicate:
Can a main function call itself in C ++?
I found this problem very interesting, but illusory. Question 6.42 C ++, how to program Dietel "Can you call main recursively on your system? Write a program containing the main function. Turn on the Static local variable count and initialize to 1. Gradually increment and print the count value each time main is called. programs What is happening?
I wrote a program as shown below, but instead I made recursion stops 10 times, as if I supported it, it would stop with a value of about 41000.
my question is: how to legally call the main function recursively in C ++, should this program be executed for the stack by thread or memory error, etc.? Explain, please.
#include <iostream> using namespace std; int main() { static int count = 0; count++; if(count <= 10) { cout << count << endl; return main(); //call main }//end if system("pause"); return 0;//successful completion }//end main
Thank you
Sinan source share