0
Is it necessary to write return 0
5 Answers
+ 6
Nope, most compilers will automatically do a return 0; once it sees that it doesnt need to do anything else in main.
+ 1
Most C++ compilers do not *require* it, and if you do not explicitly write it, they will insert it themselves at compile time. However, it is an error code expected by the OS: returning 0 indicates a completely successful run, whilst returning a nonzero value indicates that some sort of error occurred at runtime.
I recommend always implementing it, and if your programme accepts user input, check it for errors and use different error codes to report these to the OS.
0
thanks
0
no it is not always necessary to return 0 the compiler will automatically compile and the run the program without any error
0
The return of main function was created to send signals to the caller (the OS). It is a good practice to always use return values. If you don't, the compiler will do it for you, but your code will still feel incomplete.