[C++基础]012_调戏main函数
额,有没有想过main函数能不能声明呢?咱们来试试啊!
1 #include <iostream> 2 using namespace std; 3 4 int main(); 5 6 int main(){ 7 system("pause"); 8 return 0; 9 }
完全没有问题,可见,main也是一个很普通的函数啊!
那普通函数能不能调用main函数呢?咱们再来试试啊!
1 #include <iostream> 2 using namespace std; 3 4 int main(); 5 6 void test(){ 7 main(); 8 } 9 10 int main(){ 11 test(); 12 system("pause"); 13 return 0; 14 }
编译是可以通过的,不过我们可以看到,这是一个死链,哈哈,看运行效果吧!
哦,My God,不好:
005_Inline.exe 中的 0x772115de 处有未经处理的异常: 0xC00000FD: Stack overflow
栈溢出了,死链了,哈哈!
即使你加上防死链的代码,也还是会栈溢出~~