Possible Duplicate:
Can main function call itself in C++?
I found this problem very interesting but illusive a bit. Question 6.42 C++ how to program by Dietel "Can main be called recursively on your system? write a program containing a function main. Include Static local variable count and initialize to 1. Post-increment and print the value of count each time main is called. Compile your program. What happens ?
I wrote the program as below but instead I made the recursion stops after 10 times as if I were to keep it running it will stops at a value around 41000.
my question: how is it legal to call recursively main function in c++, should this program be executed to stack over flow or memory fault, etc.. ? Please explain.
#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