C ++ void return type of main() [英] C++ void return type of main()

查看:199
本文介绍了C ++ void return type of main()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一些C ++编译器允许main函数返回类型 void 。但是操作系统不需要返回 int 类型值来指定程序是否正常结束?

Some C++ compilers allow the main function to have return type void. But doesn't the Operating System require int type value returned to specify whether the program ended well or not?

推荐答案

C ++不允许 main 拥有 void 返回类型。发布的C ++标准需要 int 。一些C ++编译器允许您使用 void ,但不推荐。一般来说,OS不关心一种或另一种方式。一个特定的操作系统可能需要一个程序给出一个返回值,但它不一定必须来自 main 的返回值。如果C ++编译器允许 void ,那么它可能提供一些其他方法来指定程序的退出代码。

C++ does not allow main to have a void return type. The published C++ standard requires it to be int. Some C++ compilers allow you to use void, but that's not recommended. In general, the OS doesn't care one way or the other. A specific OS might require a program to give a return value, but it doesn't necessarily have to come from main's return value. If the C++ compiler allows void, then it probably provides some other means of specifying the program's exit code.

这篇关于C ++ void return type of main()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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