I did not understand the use of return 0; please help | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I did not understand the use of return 0; please help

4th Jan 2018, 7:53 AM
Manish Tulsiani
Manish Tulsiani - avatar
2 Answers
+ 3
every program should output a return code after it's finished. This is used to see if the program terminated successfully or it encountered a problem and had to be terminated. return 0 in main will output the code 0 which means your program terminated successfully, anything but 0 means that there was a problem. That's why main has int as a return type and you should end your program with return 0
4th Jan 2018, 8:15 AM
bogdan
bogdan - avatar
+ 1
Entirely with @bogdan. Only addition: There are some predefined EXIT codes that are used in POSIX shells and should therefore be avoided. All EXIT codes above 127: if the program was interrupted via a SIGNAL it should exit with 128+SIGNAL. but your shell will most likely do this automatically 127: Executable not found 126: Executable not executable 125(is used by `git bisect` but you can usually ignore that): Should be used to indicate a untestable revision if this a test script to test your repo.
4th Jan 2018, 8:27 AM
romangraef