C library function - atexit()
Description
C library function *int atexit(void (func)(void)) When the program terminates normally, the specified function is called func. You can register your termination function anywhere, but it will be called when the program terminates.
Declaration
The following is the declaration of the atexit() function.
int atexit(void (*func)(void))
Parameters
- func -- Function to be called when the program terminates.
Return Value
If the function is registered successfully, it returns zero; otherwise, it returns a nonzero value.
Example
The following example demonstrates the use of the atexit() function.
#include
#include
void functionA ()
{
printf("这是函数A\n");
}
int main ()
{
/* Register termination function */
atexit(functionA );
printf("启动主程序...\n");
printf("退出主程序...\n");
return(0);
}
Let's compile and run the above program, which will produce the following result:
启动主程序...
退出主程序...
这是函数A
C Standard Library -