c – 我可以省略C中main的返回吗?

前端之家收集整理的这篇文章主要介绍了c – 我可以省略C中main的返回吗?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在C中,3.6.1主要功能

(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;

我可以在C99中执行以下操作而不返回0吗?

int main() { }

解决方法

是的,从C99开始,如果main的返回类型与int兼容,则在main返回0时到达}.

5.1.2.2.3 Program termination

If the return type of the main function is a type compatible with int,a return from the initial call to the main function is equivalent to calling the exit function with the value returned by the main function as its argument;11) reaching the } that terminates the main function returns a value of 0. If the return type is not compatible with int,the termination status returned to the host environment is unspecified.

原文链接:https://www.f2er.com/c/116631.html

猜你在找的C&C++相关文章