Google News
logo
C-Language - Interview Questions
Is it possible to call atexit() function more than once in a C program?
Yes. We can call atexit() function more than once. But, they will be executed in reverse order as a stack.
 
Example Program : 
#include <stdio.h> 
#include <stdlib.h>
 
void Exit1 (void)
{
   printf ("Exit1 function is called\n");
}
void Exit2 (void)
{
   printf ("Exit2 function is called \n");
}
 
int main (void)
{
   atexit (Exit1);
   atexit (Exit2);
   printf ("This is the end of this program.\n");
   return 0;
}
 
Output :
This is the end of this program.
Exit2 function is called
Exit1 function is called
Advertisement