JeraldtheBEAR said:
Why did they say that. Thanks for the help.
Historically programs return values to the operating system. It has been that way since systems dating back to the 1960s and earlier.
Your main() function returns a value to the OS to signal result codes. Usually for commands from the system 0 indicates success, and positive values indicate standard error codes set by the OS. The return codes are not universal, as programs like the Unix tool ‘count’ return the number of items rather than returning 0 for success. Some programs like the Windows tool ‘robocopy' return more complex error codes as bitflags; values 0-7 indicate success by setting any of the bits meaning no copying was done, or files were only added, or extra files were removed, or mismatched files were detected and copied, but all of them meaning the copy command robustly handled what was expected, values with higher bits set (values 8 or above) mean other errors happened and the command failed.
You can choose what your program returns to the operating system. This can help you write scripting tools later on which use your program as one step among many.
Rutin said:
You can omit return 0 because if you don't write a return statement it will by default.
This is a legacy feature from the 1970s and the early C language. If you do not return anything, the value 0 will be returned by the operating system.
It is classified as an intentional exception that has been included in the language, and requests to change it in language defect reports have been rejected since the beginning. The main() function is the only exception to the rule, a function specified as returning a value but then legally not returning one.
For any other function this is undefined behavior. A program might not compile, might happen to work correctly in one case, might crash, might have hidden bugs, might corrupt the stack, might allow for hacker exploits, or might even wipe the hard drive, all the regular undefined behavior warnings apply.