Can you recurse main?
ie
[code]
int main(void)
{
int x = 0;
cout << x++ << endl;
while(x<40)
main();
}
Can you recurse main?
ie
[code]
int main(void)
{
int x = 0;
cout << x++ << endl;
while(x<40)
main();
}
Yes, but it is not advised! Some compilers will give you an error/warning.
--edit-- Like salem said though, it will be an infinite loop, not recursion that has a basecase to stop the recursion.
Last edited by stumon; 06-30-2003 at 04:09 PM.
The keyboard is the standard device used to cause computer errors!
>> If you really must do it
Though I really see no reason why you ever would need to.
The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.
>>Yes, but it is not advised!
No, C++ doesn't allow recursive calls to main...ever. You can try to compile as C, then you can recursively call main, but that's not the same question.
>>Some compilers will give you an error
Yes, that would be C++ compilers.
>> Yes, that would be C++ compilers.
Only completely standard compliant compilers. I have seen C++ compilers allow people to call main recursively with little more than a small warning to the effect of, "You shouldn't do this."
The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.
Im not going to argue, im only going to post this once. Put this in your compiler.Originally posted by Casey
>>Yes, but it is not advised!
No, C++ doesn't allow recursive calls to main...ever. You can try to compile as C, then you can recursively call main, but that's not the same question.
>>Some compilers will give you an error
Yes, that would be C++ compilers.And it will work depending on your compiler! infinite loop! Not exactly recursion, but similar. That was my answer! VSC++ will allow this with no errors/warnings. Some others will not.Code://filename blah1.cpp #include <iostream> int main() { std::cout << "Blah"; main(); return 0; }
The keyboard is the standard device used to cause computer errors!