C library functions -atexit()
C Standard Library - <stdlib.h>
Description
C Library Functionsint atexit(void (*func)(void))When the program terminates normally, the specified function is called.funcYou 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))
Parameter
- func-- The function to be called when the program terminates.
Return Value
If the function is registered successfully, the function returns zero; otherwise, it returns a non-zero value.
Example
The following example demonstrates the usage of the atexit() function.
#include <stdio.h>
#include <stdlib.h>
void functionA ()
{
printf("这是函数A\n");
}
int main ()
{
/* 注册终止函数 */
atexit(functionA );
printf("启动主程序...\n");
printf("退出主程序...\n");
return(0);
}
Let us compile and run the above program, which will produce the following result:
启动主程序... 退出主程序... 这是函数Aother extensions