Difference between return Statement and exit() Function

The differences between the return Statement and exit() Function are as follows:

return Statement

exit() Function

The return statement is a keyword. exit() is a function.
It is part of the language. It is part of the Standard Library <stdlib.h>
It is used to return the program control to the calling function.  It is used to terminate the current process.
When the return is used in main(), all the objects are destroyed whether they are local or static. When the exit() is used, only the destructor of static objects is called.


Return Statement vs Exit() in main() in C++

The return statement in C++ is a keyword used to return the program control from the called function to the calling function. On the other hand, the exit() function in C is a standard library function of <stdlib.h> that is used to terminate the process explicitly.

The operation of the two may look different but in the case of the main() function, they do the same task of terminating the program with little difference. In this article, we will study the difference between the return statement and exit() function when used inside the main() function.

Similar Reads

exit() Function in main()

When exit() is used to exit from the program, destructors for locally scoped non-static objects are not called. The program is terminated without destroying the local objects....

return Statement in main()

...

Difference between return Statement and exit() Function

...

Contact Us