Using atexit

With the atexit function, you can specify an exit-processing function that executes prior to program termination. No global static objects initialized prior to the call to atexit are destroyed prior to execution of the exit-processing function.

See Also

Reference

Additional Termination Considerations