What#39;s the meaning of the return value of int main(), and how to display it?(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()的返回值是什么意思,如何显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:int main()的返回值是什么意思,如何显示?


基础教程推荐
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 我有静态或动态 boost 库吗? 2021-01-01
- 常量变量在标题中不起作用 2021-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 这个宏可以转换成函数吗? 2022-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07