<分区>
Possible Duplicate:
Error handling in C code
What return value should you use for a failed function call in C?
我总是使用 0,但它在 if
、while
等中并不是真正可读的。
我应该返回 1 吗?为什么 main 函数 返回 0
表示成功?
<分区>
Possible Duplicate:
Error handling in C code
What return value should you use for a failed function call in C?
我总是使用 0,但它在 if
、while
等中并不是真正可读的。
我应该返回 1 吗?为什么 main 函数 返回 0
表示成功?
最佳答案
C 标准将其定义为 0
表示成功(功劳归于 hvd)。
For greater portability, you can use the macros
EXIT_SUCCESS
andEXIT_FAILURE
for the conventional status value for success and failure, respectively. They are declared in the filestdlib.h
.
(我说的是从 main、exit 或类似调用返回到操作系统的值)
至于你的函数,只要你在你的程序中保持这种方式,就返回你想要的并使代码更具可读性。
关于c - 我应该为成功的函数返回 0 还是 1?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9549342/