main() function calls itself in C++, what will happen? [duplicate]
问题 This question already has answers here : Is it legal to recurse into main() in C++? [duplicate] (5 answers) Is this code valid under any C standard? (3 answers) Closed 6 years ago . #include <iostream> int main() { main(); std::cout<<"Hello World! "<<std::endl; return 0; } This is the code, How does it behave? Why? 回答1: That's undefined behaviour. You cannot call main() from within a C++ program (section 3.6.1.3 of the standard). Therefore anything can happen. And there's no point in asking