如果将返回值设置为17而不是1或0会发生什么?请指导我...... [英] What will happen if set the return value to 17 rather than 1 or 0 ? kindly guide me...

查看:147
本文介绍了如果将返回值设置为17而不是1或0会发生什么?请指导我......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

What will happen if set the return value to 17 rather than 1 or 0 ??Kindly guide me...





我尝试过:





What I have tried:

What will happen if set the return value to 17 rather than 1 or 0 ??Kindly guide me...

推荐答案

没什么!



每个函数都可以返回任何值。区别在于 main 功能。



Nothing!

Every function may return any value. The difference is with main function.

Quote:

当main返回零(隐式或显式)时,环境将其解释为程序成功结束。 main可以返回其他值,并且某些环境以某种方式向调用者提供对该值的访问,尽管这种行为不是必需的,也不一定在平台之间可移植。在所有平台上保证以相同方式解释main的值...

When main returns zero (either implicitly or explicitly), it is interpreted by the environment as that the program ended successfully. Other values may be returned by main, and some environments give access to that value to the caller in some way, although this behavior is not required nor necessarily portable between platforms. The values for main that are guaranteed to be interpreted in the same way on all platforms...





请参阅:

功能 - C ++教程 [ ^ ]

主要功能 - cppreference.com [ ^ ]


取决于返回值类型是什么以及确切地说 - 该方法应该做什么。

在C和C ++中,任何非零值实际上都是真,零单独表示假。

因此,如果函数返回值正在条件中使用:

Depends on what the return value type is and what - exactly - the method is supposed to do.
In C and C++, any non-zero value is effectively "true" and zero alone represents "false".
So if you function return value is being used in a conditional:
if (MyFunctiuon())
   {
   ...

然后返回十七(或一个)洪特红色和八十)而不是一个将没有任何区别。



如果函数在返回时做的是 main 函数,然后是,它将 - 0表示没有错误,正常终止,而任何其他值是错误代码(可以转换为错误消息来解释为什么它是一个问题)。

Then returning seventeen (or one hundred and eighty) instead of one will make no difference.

If the function do in the return is the main function, then yes, it will - 0 indicates "no error, normal termination" while any other value is an error code (which can be translated to an error message to explain why it's a problem).


这篇关于如果将返回值设置为17而不是1或0会发生什么?请指导我......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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