C 语言中 int main() 和 void main() 有何区别?
的有关信息介绍如下:
@SuperSodaSea 在评论中提到,main是个特例(which I didn't notice in the first place), 5.1.2.2.3 #1,
非常感谢。
----
原答案:
这个时候应该引用ISO/IEC 9899:1999文档(或是ISO/IEC 9899:2011,取决于你学的是哪个版本的C语言)(Programming languages -- C)的5.1.2.2.1 #1,(由于我没有找到免费的2011的文档,所以用Google上的第一个关于ISO/IEC 9899:1999的免费结果……)
以及同文档的6.9.1 #12……
5.1.2.2.1 #1提到“......or in some other implementation-defined manner”,所以你的编译器或许也提供了其它的program startup给你,但是只要是符合标准的编译器,一定会有这里说明的两种startup。
而6.9.1 #12则提到了“If the } that terminates a function is reached, and the value of the function call is used by the caller, the behavior is undefined.”,所以不写return是真的undefined behavior。



