Joona I Palaste said:
The difference between return and exit() is that return only ends the
current function, while exit() ends the whole program. In main(),
return and exit() are identical.
Only in a sane program. If you call main() recursively (or, even worse,
indirectly recursively), returning from main() will only return from the
current invocation, and exit() is (more or less) equivalent to a return
from the outermost (i.e., first) call of main().
And then there is the jolly trick of using atexit() functions which
require that local variables in main() still exist, or similar
perversions using setbuf().
Clearly, neither of these behaviours are in the least recommendable in a
well-behaved, sanely written C program. But they can occur, and when
they do, there is a difference between exit() and return from main().
Richard