What does 'return 0;' literally means?

It's my 4th day here and i'm on Classes (I) part now. I just notice some examples always has 'return 0;'. As far as i know main function should return 0 and return -1 means failure. But don't really get it at all my brain is going to explode trying to understand this. Btw programming really rocks! this is the first time in my life i've spent 6-8 hours learning on internet :)
Let's say FunctionA calls FunctionB.

When FunctionB is done executing, execution resumes in FunctionA at the point immediately following the call. i.e. when you "return" from a function, you terminate the execution of a function, and you transfer control back to the calling function. Functions can also return stuff (like values), which are then interpreted by the calling function.

Similarly, when the main() function terminates, it transfers control back to the operating system. According to the standard, main() has a return type of int, and it should return 0 to indicate a successful exit status.

One way of demonstrating this would be to look at an installer package. If you terminate the installation half-way through, the installer will terminate with an unsuccessful exit status - probably by returning 1 or -1. It's then up to the operating system how it should interpret the error code, and in this case, it would do so by popping up a dialog, asking if the program installed correctly.
OMG! Thank you I really understand now!
BTW, don't return negative numbers from main. For maximum portability and/or safety, keep it to 0..127. Unless you are doing something unusual anyway, you only need 0 (application terminated successfully) and 1 (application terminated reporting error).

Hope this helps.
Topic archived. No new replies allowed.