Thursday, October 28, 2010

diff between exit(0) and return(0)

Returning a value from main() and calling exit() with
that value are almost perfectly equivalent. The subtle
difference is that the local `auto' variables in main()
cease to exist when main() returns, so if any program
cleanup code -- atexit() routines, the automatic flushing
and closing of open I/O streams, and so on -- tries to
use these variables, there will probably be trouble that
wouldn't occur if exit() had been called instead.

No comments: