Let's see if I can combine the various links provided by others into an appropriate answer.
As for the C language, there is no difference.
Calling exit() calls
- calling functions registered with
atexit() ; - cleans and closes output streams;
- deletes files opened with
tmpfile() ; - returns control to the environment.
A return <n> from main is equivalent to exit( <n> ) .
Some erroneous static code analyzers think differently.
As for the C language, the memory leak allocated by main() , not free() d. Unix cleans up at the end of the process, but not all operating systems (!).
Apparently, some static code analyzers believe that the memory still allocated at exit() was not skipped (while they do for return from main() ) , therefore this commit was done (to get rid of the warning )
This is a workaround for errors in the code analyzer.
As for the C ++ language, there is a big difference.
When you return from main() , you leave the scope, which means that local objects will be destroyed.
Since C ++ programmers take advantage of deterministic destruction (unlike, for example, Java, which could or could not execute your destructor even when VM was finished ...), they usually do their destructors more than just freeing up memory. Network connections, temporary files, terminal windows blocked with ncurses are all good that C programmers will have to take care of them manually or use atexit() for.
When you call std::exit() from main() , this function directly transfers control at runtime. The main() function never returns, the process ends without calling the main() -local object destructors.
In addition, while std::exit() is defined as hiding and closing C output streams, there is no such condition for C ++ streams.