Write a C program to check the atexit() function

CServer Side ProgrammingProgramming

The atexit() is a function that allows the user to register a function that has to be called based on program termination.

It is a predefined function that is included in stdlib header files.

Example 1

 Live Demo

#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;
}

Output

Welcome to New,World

Example 2

 Live Demo

#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;
}

Output

This is a beautiful,Wonderful life
raja
Published on 06-Mar-2021 07:50:41
Advertisements