Development/C

c - return vs exit

linuxism 2016. 3. 16. 21:26


return exits from the function while exit exits from the program.

In main function executing return 0; statement or calling exit(0) function will call the registered atexit handlers and will cause program termination.


source - http://stackoverflow.com/questions/17383015/difference-between-return-0-and-exit-0







  • return is an instruction of the language that returns from a function call.
  • exit is a system call (not a language statement) that terminates the current process.

The only case when both do the same thing is in the main() function, as a return from main performs an exit().



source - http://stackoverflow.com/questions/3463551/what-is-the-difference-between-exit-and-return