那么,是什么"返回0"实际上意味着什么呢? [英] So what does "return 0" actually mean?
问题描述
我是pretty在PHP精通,但我已经开始涉足C.我见过的code
返回0;
在没有返回值的函数结束。这不是在PHP使用的,因为如果一个功能是不具有返回,自动地返回一个NULL值。
所有我问的是,在简单的英语,什么是返回0
实际上做?是像PHP,它返回它的参数作为函数调用的价值?难道只是好的做法呢?
我知道这个问题已经被问过很多次,但我要求它从一个PHP开发人员的点。谷歌抛出了这些问题的答案都没有那么简洁。
是不是如PHP,它返回它的参数作为的价值
函数调用?难道只是好的做法呢?
块引用>是的,PHP和许多其他语言借用了'C'的
收益
关键字。而在所有的语言中,收益
关键字具有相同的功能 - 从函数返回。随后收益
关键字什么是返回给调用者的值。这是一个好的做法呢? Yes和No.并非所有功能应返回一个值。而且相当标准库中的少数人甚至,不返回任何值。因此,他们的返回类型是
无效
。但
主
函数返回0
(也是EXIT_SUCCESS
),以确定该方案已成功执行。和-1否则(也EXIT_FAILURE
)编辑:(感谢@KeithThompson):
EXIT_FAILURE
是实现定义。1
是EXIT_FAILURE
的共同价值,但整点是,你不需要知道。I'm pretty proficient in PHP, but I've started dabbling with C. I've seen the code
return 0;
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.
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?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.
解决方案Is it like php, where it returns its argument as the value of the function call? Is it just good practise?
Yes, PHP and many other languages borrowed the
return
keyword from 'C'. And in all the languages, thereturn
keyword has the same function - to return from the function. Anything that followsreturn
keyword is the value that is returned to the caller.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
.But
main
function should return0
(alsoEXIT_SUCCESS
) to identify that the program has executed successfully. And -1 otherwise (alsoEXIT_FAILURE
)EDIT: (Thanks to @KeithThompson):
EXIT_FAILURE
is implementation defined.1
is a common value ofEXIT_FAILURE
but the whole point is, you need not know.这篇关于那么,是什么"返回0"实际上意味着什么呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!