为什么这里又没有return0了?什么时候需要有return 0?(语言-c语言)

img


为什么这里又没有return0了?什么时候需要有return 0?(语言-c语言)

需不需要返回值看你的方法你的方法int main就是要返回一个整形,比如说return 0
你的方法void main就是不需要返回值,就不需要写return

int main()需要返回值,用return 0. void main()不需要返回值,不用return 0. 自定义函数定义什么类型的就返回什么类型得值

C/C++中main函数比较特殊,如果mainreturn语句被省略,那么它等价于return 0;

https://en.cppreference.com/w/c/language/main_function

If the return type is compatible with int and control reaches the terminating }, the value returned to the environment is the same as if executing return 0;.