为什么我们需要在C ++中使用`int main`而不是`void main`? [英] Why do we need to use `int main` and not `void main` in C++?

查看:171
本文介绍了为什么我们需要在C ++中使用`int main`而不是`void main`?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我们需要在C ++中使用 int main 而不是 void main

Why do we need to use int main and not void main in C++?

推荐答案

简短的答案是因为C ++标准需要 main()才能返回 int

The short answer, is because the C++ standard requires main() to return int.

你可能知道, main()的返回值函数由运行时库用作进程的退出代码。 Unix和Win32都支持从进程完成后返回的(小)整数的概念。从中返回值main()为程序员指定此值提供了一种方法。

As you probably know, the return value from the main() function is used by the runtime library as the exit code for the process. Both Unix and Win32 support the concept of a (small) integer returned from a process after it has finished. Returning a value from main() provides one way for the programmer to specify this value.

这篇关于为什么我们需要在C ++中使用`int main`而不是`void main`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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