atexit()는 프로그램 종료에 따라 호출해야 하는 함수를 사용자가 등록할 수 있도록 하는 함수입니다.
stdlib 헤더 파일에 포함되어 있는 미리 정의된 기능입니다.
예시 1
#include<stdio.h>
#include<stdlib.h>
void welcome(void){
printf("Welcome to New,");
}
void world(void){
printf("World\n");
}
int main(){
//test atexit ,call user defined function
atexit(world);
atexit(welcome);
return 0;
} 출력
Welcome to New,World
예시 2
#include<stdio.h>
#include<stdlib.h>
void first(void){
printf("This is a beautiful,");
}
void second(void){
printf("Wonderful life\n");
}
int main(){
//test atexit ,call user defined function
atexit(second);
atexit(first);
return 0;
} 출력
This is a beautiful,Wonderful life