+ 8
Why do we write "return 0;" and not anything else (for example NULL) after the int main() function. And if I wanna return exactl
4 Respuestas
+ 8
The return value of main can be checked in system, when program ended. So, is there such convention.
return 0; means the program ended OK
return other integer value means the program ended with any error
Of course you can define other meaning of returning integer value, and describe it it your program documentation and help
Return anything else than integer is not a clever idea, it can cause any mash..
+ 2
Well it depends on the return data type of the function which has return statement in it. We usually write return 0 if he have declared main to return an integer as in int main(). That means that the program ended correctly. We could also write void main() and return no value though its not according to standards. Anyway even if you don't return anything the compiler will "add" a return 0 for you.
NULL it's not allowed
0
I found it very confusing, that 0 is usually returned, when a function worked correctly. Since 0 stands for false in conditions...
Also MPI functions return 0 if successful for example.
Weird convention.
- 2
I upvoted you petr just so you get the new badge 😁