为什么我们在C语言中使用return 0? [英] why do we use return 0 in C language ?

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

问题描述

为什么我们在C语言中使用返回0 如果我们可以运行程序或在没有程序的情况下执行任何操作?

Why do we use return 0 in C language if we can run a program or do whatever with program without it ?

推荐答案

谷歌怎么样?

例如请参阅 http://bash.cyberciti.biz/guide/The_exit_status_of_a_command [ ^ ]。

请注意,C是为那些日子将Unix移植到各种计算机而开发的。所以,任何命令的退出代码的概念都可能在Unix的shell概念中有其根源。

问候

Andi
How about Google?
E.g. see http://bash.cyberciti.biz/guide/The_exit_status_of_a_command[^].
Note that C was developed for porting Unix to various computers those days. So, the concept of exit code of any command may have its root in Unix's shell concept.
Regards
Andi


返回指示程序如何成功终止或以其他方式终止。由于错误状态可能需要更多解释而不是程序成功完成,因此选择0表示成功(即如果您未能执行则只需要更多详细信息)。



大多数程序都有一系列失败的返回值,这些返回值对应于某些错误代码(例如,1个无法打开文件,2个未能写入文件,3个文件未找到,依此类推)。这允许正在执行应用程序的操作员和/或脚本知道它失败的原因,而不仅仅是它已经失败。
The return indicates how a program terminated, either successfully or otherwise. Since the error state likely needs more of an explanation than if a program finishing successfully, 0 was chosen to indicate success (i.e. you only need more details if you've failed to execute).

Most programs have an assortment of failed return values that correspond to some error codes (for example, 1-failed to open file, 2-failed to write to file, 3-file not found, so on). This allows the operator and/or script that's executing your application to know why it failed, not simply that it has failed.


大多数程序返回错误代码;这样用户可以修复或跟踪错误。



所以'0'表示没有错误。
most programmes return error code; so that the user can fix or track the error if it occures.

so '0' means no error.


这篇关于为什么我们在C语言中使用return 0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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