Why is return 0 optional?

后端 未结 4 1425
遥遥无期
遥遥无期 2020-11-27 21:48

Why, if I write

int main() 
{ 
    //... 
}

do I not need to write return 0; at the end of the main function? Do

4条回答
  •  眼角桃花
    2020-11-27 22:12

    Basically, yes. Functions are not required to return anything, even if they declare a return type other than void. The value returned will be undefined.

    Note that C99 requires that functions that declare non-void return types always terminate by hitting a return statement. So if you were compiling using your compiler's C99 mode this code would result in a compile-time error.

提交回复
热议问题