gpt4 book ai didi

c++ - 为什么这个程序总是崩溃

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:00:35 25 4
gpt4 key购买 nike

它在执行时崩溃:

#include <iostream>

int main ()

{
if(main());
return 0;
}

为什么?

最佳答案

它因 Stackoverflow 而崩溃当然,因为没有终止条件,但从技术上讲,C++ 编译器不允许编译它,因为在 C++ 中:

main() cannot be called from within a program.
The address of main() cannot be taken.
The main() function cannot be overloaded.

标准内容:

C 兼容性附件

3.6

Change: Main cannot be called recursively and cannot have its address taken
Rationale: The main function may require special actions.
Effect on original feature: Deletion of semantically well-defined feature
Difficulty of converting: Trivial: create an intermediary function such as mymain(argc, argv).
How widely used: Seldom

关于c++ - 为什么这个程序总是崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5759039/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com