在ISO C ++中/反对从main返回0的原因是什么? [英] What the reasons for/against returning 0 from main in ISO C++?

查看:44
本文介绍了在ISO C ++中/反对从main返回0的原因是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道C ++标准规定,如果未给出return语句,则在 main()的末尾插入 return 0 .但是,我经常看到最近编写的,符合标准的C ++代码,该代码在 main()的末尾显式返回0.出于什么原因,如果编译器自动完成,有人想显式地返回0?

I know that the C++ standard says that return 0 is inserted at the end of main() if no return statement is given; however, I often see recently-written, standard-conforming C++ code that explicitly returns 0 at the end of main(). For what reasons would somebody want to explicitly return 0 if it's automatically done by the compiler?

推荐答案

因为看起来很奇怪,无法从具有非无效返回类型的函数中返回"某些内容(即使该标准说严格没有必要).

Because it just looks weird to not "return" something from a function having a non-void return type (even if the standard says it's not strictly necessary).

这篇关于在ISO C ++中/反对从main返回0的原因是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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