c++ - 程序编译有无返回 0

标签 c++ return statements

<分区>

Possible Duplicate:
What should main() return in C/C++?

我想这是一个非常基本的问题。

我已经编程一年了,但我的一个 friend 提出了一个相当令人震惊的问题,这让我感到惊讶。

在 C++ 上以“int main()”开头的程序似乎可以完美编译,即使使用“return 0;”也是如此已删除且未被任何其他 return 语句替换。并且根本没有 return 语句,程序仍然显示“Process returned 0”。

这有什么解释吗? 对不起,如果我的问题很愚蠢!

最佳答案

§3.6.1/5:

A return statement in main has the effect of leaving the main function (destroying any objects with automatic storage duration) and calling exit with the return value as the argument. If control reaches the end of main without encountering a return statement, the effect is that of executing return 0;

关于c++ - 程序编译有无返回 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3379843/

相关文章:

java - 如何在java上用if语句结束一个结果?

c++ - 指向对象的指针数组不会填满其分配的容量

c++ - 删除复制赋值运算符的 VS 2015 Update 3 错误

java - 为什么不打印此代码?有什么错误?

c中的函数可以返回long int吗?

Excel IF "text"然后是数字,如果另一个 "text"然后是另一个数字

c++ - 我可以在 C 或 C++ 中使用二进制文字吗?

c++ - Windows 上的 std::map::operator[] 违规访问内存

python - 如何测试可变的隐含结果?