Recursive call on main C++
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/2128321/can-main-function-call-itself-in-c">Can main function call itself in C++?</a>  </p>
</blockquote>



<p>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 ?</p>

<p>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.</p>

<p>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.</p>

<pre><code>#include &lt;iostream&gt;
using namespace std;
int main()
{
       static int count = 0;
       count++;
       if(count &lt;= 10) {
                cout &lt;&lt; count &lt;&lt; endl;
                return main(); //call main
                }//end if

       system("pause");
       return 0;//successful completion
}//end main
</code></pre>

<p>thank you</p>
