[C ++]在main()中,返回0个问题 [英] [C++] In main() , return 0 problems

查看:47
本文介绍了[C ++]在main()中,返回0个问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

int main()
{
    .......
    return 0;
}



众所周知, return 0;用于终止程序.但是值返回到哪里?
请帮助我解决这个愚蠢的问题.谢谢=]



As we know, return 0; is used for terminating a program. But where is the value returns to ??
Please help me with this silly question. Thank you =]

推荐答案

到操作系统.
例如,请参见如何在 Windows上看到这样的返回值(由竞争对手"提供)...:
To the Operating System.
See, for instance, how can you see such return value on Windows (courtesy of ''the competitors''...):"how do I get the application exit code from a Windows command line[^] at StackOverflow.


阅读此书 [
Read this[^]...

Those return values are used to know the exit status of an app... (i.e. you could call an app from yours and you could be interested on knowing how has it finished).

HTH! :thumbsup:


不! 返回0不用于终止程序!谁告诉过你?

返回值称为退出代码.

在Windows上,关闭应用程序后,可以通过批处理文件或父进程中的代码(通过Windows API CreateProcesCreateProcessEx)检查退出代码值.
(感谢C Pallini指出这仅适用于Windows;我忘了提及它.)

在其他系统(至少所有类似Unix的系统以及其他基于Posix的Windows,包括Windows)中,退出代码也可以由命令解释器和父进程进行检查.传统上,0表示没问题",成功",但是退出代码可以表示任何含义,这是特定于应用程序的.在当今的实践中,很少使用.

这就是您需要了解的所有内容.

—SA
No! Return 0 is not used to terminate a program! Who told you so?

The return value is called exit code.

On Windows, exit code value can be examined by batch file or a code in parent process (via Windows API CreateProces or CreateProcessEx) after the application is closed.
(Thanks to C Pallini for pointing out that this is applicable to Windows only; I forgot to mention it.)

In other system (at least all Unix-like ones and other Posix-based which includes Windows), the exit code can also can be examined by the command interpreters and the parent processes in general. Traditionally, 0 is used to indicate "no problem", "success", but the exit code can mean anything at all, this is application-specific. In present-day practice, used rarely.

That''s all you need to know about it.

—SA


这篇关于[C ++]在main()中,返回0个问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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