With the function atexit() it is possible to set a function that will be executed on termination of the program.

Usage of atexit():

int atexit ( void ( * func ) (void) );

If the program is terminated normally then the function pointed by the func pointer argument is called.
If there are more then one atexit functions (multiple calls) then they are all executed in reverse order as the where stacked.
(Which means that the last function specified is first to execute at exit of the program.)Note: one single function can be executed more then once on exit.

Parameters:

Function that needs to be called.

Note: the function cannot return an argument and the function cannot accept arguments.

Return value:

A non zero is returned if it fails and a zero is returned if it was successful.