且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C ++为什么main工作没有返回值

更新时间:2022-05-17 21:41:11

通常不允许控制流到达非空函数的结尾而不返回任何东西。 main 函数的处理方式与标准中指定的不同。

Normally it is not allowed for the control flow to reach the end of a non-void function without returning something. The main function is handled differently, as specified in the standard.

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/ n2960.pdf

§3.6.1 / 5

如果控制到达main结尾而没有遇到返回
语句,效果是执行return 0;

If control reaches the end of main without encountering a return statement, the effect is that of executing return 0;

至于理由,我不敢肯定。如果有人知道,请将其添加到我的回答或作为评论。

As for the rationale, I'm not sure, honestly. If someone knows, please add it to my answer or as a comment.