Pointer to a function that takes no arguments and returns no value
1st Parameter
Pointer to a function with no parameters and no return value, to be called on program termination
Read more about parameters of atexit in parameters section
The atexitfunction in C language Registers a function to be called at program termination.
The atexit function registers the given function to be called automatically when the program terminates normally. This is useful for performing cleanup operations, closing files, or freeing resources. Multiple functions can be registered, and they will be called in the reverse order of their registration. The registered functions should not use their return value and should not take any parameters.
The atexitfunction takes 1
parameter:
•
void (*)(void) `func`: Pointer to a function with no parameters and no return value, to be called on program termination
Registers a function to be called automatically upon normal program termination. Functions are executed in the reverse order of their registration.
The atexit function return value :
Returns 0 if the function is successfully registered, non-zero if it fails
Output
This example demonstrates registering multiple functions with `atexit`. These functions will be called in reverse order when the program terminates.