问题描述
我是pretty在PHP精通,但我已经开始涉足C.我见过的code
返回0;
在没有返回值的函数结束。这不是在PHP使用的,因为如果一个功能是不具有返回,自动地返回一个NULL值。
所有我问的是,在简单的英语,什么是返回0
实际上做?是像PHP,它返回它的参数作为函数调用的价值?难道只是好的做法呢?
我知道这个问题已经被问过很多次,但我要求它从一个PHP开发人员的点。谷歌抛出了这些问题的答案都没有那么简洁。
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.
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 return 0
(also EXIT_SUCCESS
) to identify that the program has executed successfully. And -1 otherwise (also EXIT_FAILURE
)
EDIT: (Thanks to @KeithThompson):
EXIT_FAILURE
is implementation defined. 1
is a common value of EXIT_FAILURE
but the whole point is, you need not know.
这篇关于那么,是什么"返回0"实际上意味着什么呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!