Our first recipe will be to register a function that executes automatically when a program terminates normally. For this recipe, we will be using the atexit() function.
The atexit function is set to point to a function; this function is automatically called without arguments when the program terminates. If more than one atexit function is defined in a program, then these functions will be called in the Last In, First Out (LIFO) order, that is, the function pointed to last by the atexit function will be executed first, followed by the second to last one, and so on.
The atexit function accepts a single mandatory parameter: the pointer to the function to be called on program termination. Additionally, the function returns 0 if the function is registered successfully, that is, the function to be invoked is...