0
using Return 0; or not. whats the difference actually?
When i use return 0; the output is just as same as when i dont use return 0; then why we should use it?
4 odpowiedzi
+ 6
The standard says that it is OK, to omit the return statement for main().
http://www.stroustrup.com/bs_faq2.html#void-main
+ 5
If a function is declared to return a value and fails to do so, the result is undefined behavior (in C++) When we don't declare return 0. One possible result is seeming to work.
As an aside, in C, you wouldn't actually have undefined behavior -- in C, you get undefined behavior only if you try to use the return value, and the function didn't specify a value to return.
+ 4
We return 0 in the main function to indicate to the environment the fact that the program worked as expected. You can return a non-zero value to indicate an error.
Generally, if you omit it, the compiler will append it at the end of the main function.
+ 1