Write a C program to check the atexit() function


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
"); } 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
"); } int main(){    //test atexit ,call user defined function    atexit(second);    atexit(first);    return 0; }

Output

This is a beautiful,Wonderful life

Updated on: 06-Mar-2021

360 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements