通用工具库stdlib.h里好玩的函数

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

void a(void)
{
    printf("%s\n","this is a;");
}

void b(void)
{
    printf("%s\n","this is b;");
}

void c(void)
{
    printf("%s\n","this is c;");
}

int main()
{
    printf("%s\n","this is main first;");
    //在程序结束时按照相反的顺序运行函数
    atexit(a);
    atexit(b);
    atexit(c);

    printf("%s\n","this is main;");

    exit(EXIT_SUCCESS);

    printf("%s\n","this is main 2;");
}

结果为
this is main first;
this is main;
this is c;
this is b;
this is a;

1. exit()

函数exit强制终止程序的运行。

2.atexit()

在程序结束时(包括被exit()打断的)按照相反的顺序运行函数

猜你喜欢

转载自blog.csdn.net/qq_36769966/article/details/96752502