Latest web development tutorials

C library functions - atexit ()

C standard library - <stdlib.h> C standard library - <stdlib.h>

description

C library functionsint atexit (void (* func) (void)) when the program terminates normally, call the specified function func.You can register your termination function anywhere, but it will be called when the program terminates.

statement

Here is () statement atexit function.

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

parameter

  • func - function is called when the program terminates.

return value

If the function is successfully registered, the function returns zero, otherwise a non-zero value.

Examples

The following example demonstrates the atexit () function is used.

#include <stdio.h>
#include <stdlib.h>

void functionA ()
{
   printf("这是函数A\n");
}

int main ()
{
   /* 注册终止函数 */
   atexit(functionA );
   
   printf("启动主程序...\n");

   printf("退出主程序...\n");

   return(0);
}

Let's compile and run the above program, which will result in the following:

启动主程序...
退出主程序...
这是函数A

C standard library - <stdlib.h> C standard library - <stdlib.h>