Program run without return

The program runs fine without any return i wanna know what's return statement do exactly?
It returns the value to the caller. If you leave out the return statement from main it will automatically return 0 (meaning the program ended correctly). If you leave out the return statement from a non-void function other than main the behaviour is undefined which means that there is no guarantees what will happen. It might work, but don't rely on it.
return sends a value back to the caller and exits the current function.

int foo()
{
return 3;
}

x = foo(); //return 3 sends the 3 back and it will land in x.


in main (and only in main), return sends the value back to the *operating system* and exits the program.


in void functions, it exits the function only, no value is sent.
Topic archived. No new replies allowed.