int main()的返回值是什么意思,如何显示? [英] What's the meaning of the return value of int main(), and how to display it?

查看:20
本文介绍了int main()的返回值是什么意思,如何显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
main() 在 C/C++ 中应该返回什么?

我有这个简单的 C 程序:

I have this simple program in C:

#include <stdio.h>

int main()
{
  return 8;
}

返回值是什么意思,如何显示,或者如何使用?

What's the meaning of the return value, and how to display it, or how to use it?

推荐答案

返回值是什么意思?

用于将main()函数的状态返回给main()的调用者:

It is used to return the status of the main() function to the caller of main():

参考:
C++03 标准:18.3 开始和终止

最后,控制权返回到宿主环境.如果状态为零或 EXIT_SUCCESS,则返回成功终止状态的实现定义形式.如果状态是EXIT_FAILURE,返回状态不成功终止的实现定义形式.否则返回的状态是实现定义的.

Finally, control is returned to the host environment. If status is zero or EXIT_SUCCESS, an implementation-defined form of the status successful termination is returned. If status is EXIT_FAILURE, an implementation-defined form of the status unsuccessful termination is returned. Otherwise the status returned is implementation-defined.

如何展示,或者如何使用?

就像显示或使用任何其他函数的返回值一样.main() 只是 C/C++ 中的另一个函数,在这方面 main 没有什么特别之处.

Just as you would display or use return value of any other function. main() is just another function in C/C++ there's nothing special about main in that regards.

这篇关于int main()的返回值是什么意思,如何显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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