那么“return 0"是什么意思?实际上是什么意思? [英] So what does "return 0" actually mean?

查看:26
本文介绍了那么“return 0"是什么意思?实际上是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我非常精通 PHP,但我已经开始涉足 C.我看过代码

I'm pretty proficient in PHP, but I've started dabbling with C. I've seen the code

return 0;

在不返回值的函数的末尾.这在 PHP 中没有使用,因为如果函数没有返回值,则会自动返回值 NULL.

at the end of functions that don't return a value. This isn't used in PHP, because if a function is doesn't have a return, a value NULL is automatically returned.

我要问的是,用简单的英语,return 0 实际上是做什么的?是否像 PHP 一样,将其参数作为函数调用的值返回?这只是一种好的做法吗?

All I'm asking is, in simple English, what does the return 0 actually do? Is it like PHP, where it returns its argument as the value of the function call? Is it just good practice?

我知道这个问题以前被问过很多次,但我是从 PHP 开发人员的角度来问的.谷歌给出的答案并没有那么简洁.

I know this question has been asked many times before, but I'm asking it from the point of view of a PHP developer. The answers google throws up haven't been that concise.

推荐答案

它像 php 一样,它返回它的参数作为函数调用?这只是一种好的做法吗?

Is it like php, where it returns its argument as the value of the function call? Is it just good practise?

是的,PHP 和许多其他语言都从C"中借用了 return 关键字.在所有语言中,return 关键字具有相同的功能——从函数中返回.return 关键字后面的任何内容都是返回给调用者的值.

Yes, PHP and many other languages borrowed the return keyword from 'C'. And in all the languages, the return keyword has the same function - to return from the function. Anything that follows return keyword is the value that is returned to the caller.

这是一个好习惯吗?是和否.并非所有函数都应该返回一个值.甚至在标准库中也有不少,不返回任何值.因此它们的返回类型是 void.

Is it a good practise? Yes and No. Not all functions should return a value. And quite a few in the standard library even, do not return any value. Hence their return type is void.

但是main 函数应该返回0(也是EXIT_SUCCESS)来标识程序已经成功执行.否则为 -1(还有 EXIT_FAILURE)

But main function should return 0(also EXIT_SUCCESS) to identify that the program has executed successfully. And -1 otherwise (also EXIT_FAILURE)

(感谢@KeithThompson):

(Thanks to @KeithThompson):

EXIT_FAILURE 是实现定义的.1EXIT_FAILURE 的常见值,但重点是,你不必知道.

EXIT_FAILURE is implementation defined. 1 is a common value of EXIT_FAILURE but the whole point is, you need not know.

这篇关于那么“return 0"是什么意思?实际上是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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