I have tried basic implementation of atexit()
. Although return type of main()
is int
, compiler gives no error when executed without returning any value from main
.
#include <stdio.h>
#include <stdlib.h>
void my_exit1(void);
void my_exit2(void);
int main(void)
{
if (atexit(my_exit2) != 0)
printf("can't register my_exit2");
if (atexit(my_exit1) != 0)
printf("can't register my_exit1");
printf("starting main\n");
printf("main is done\n");
//return(0);
//exit(0);
}
void my_exit1(void)
{
printf("first exit handler\n");
}
void my_exit2(void)
{
printf("second exit handler\n");
}
OUTPUT:
starting main
main is done
first exit handler
second exit handler