我可以省略主要用C回报? [英] Can I omit return from main in C?

查看:92
本文介绍了我可以省略主要用C回报?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C ++中,3.6.1主要功能


  

(3.6.1 / 5)主要return语句有离开的主要功能(破坏具有自动存储时间的对象)的影响,
  调用的返回值作为参数退出。 如果控制到达
  主而不会遇到return语句结束时,效果是
  该执行返回0;


我可以做如下的C99​​不返回0?

  INT的main(){}


解决方案

是的,作为C99的,达到了} 在主返回0结束时,如果返回类型的是兼容 INT


  

5.1.2.2.3计划终止


  
  

如果在函数的返回类型为int类型兼容,从最初的调用的返回的功能相当于调用退出函数作为参数返回的值函数; < SUP> 11)达到} 终止的函数返回值为0。如果返回类型是不符合 INT 兼容,终止状态返回到主机环境是不确定的。


In C++, 3.6.1 Main function

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

Can I do the following in C99 without return 0?

int main() { }

解决方案

Yes, as of C99, reaching the } at the end of main returns 0 if the return type of main is compatible with int.

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.

这篇关于我可以省略主要用C回报?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆