0

Is it necessary to write return 0

15th Apr 2017, 6:39 AM
Shivam
Shivam - avatar
6 Answers
+ 6
Nope, most compilers will automatically do a return 0; once it sees that it doesnt need to do anything else in main.
15th Apr 2017, 6:48 AM
Wen Qin
Wen Qin - avatar
+ 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.
15th Apr 2017, 6:55 AM
Zack Strickland
Zack Strickland - avatar
0
thanks
15th Apr 2017, 6:51 AM
Shivam
Shivam - avatar
0
no it is not always necessary to return 0 the compiler will automatically compile and the run the program without any error
15th Apr 2017, 7:14 AM
Siddharth Upadhyay
Siddharth Upadhyay - avatar
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.
15th Apr 2017, 11:47 AM
Denis Felipe
Denis Felipe - avatar