Where does the return value go ?

int main()
{
return 0;
}

Where the return value goes ?
If the return value goes to a particular location then why it goes to that particular location ?

The return value from the main function is returned to the OS (Or rather the CLI that executed it) to signal the end of the program and also the exit code(0 here) which tells it if the process ran successfully or failed.

2 Likes

oh ok. Thanks for the information. But still i am having a doubt.If the process ran successfully then the value we have given in return will be sent to the os as exit code. But what value will be returned if the process is failed ? Is it -1 or something ? Any idea ?

Well, 0- EXIT_SUCCESS and 1- EXIT_FAILURE are 2 things I’m sure of in standard C.
Feel free to correct me if I’m wrong but I believe there are others you might pass but I think those would be more platform specific in both size and meaning. You’ll need to look those up depending on your system.

1 Like

Thank you .

//