/*-------------------------------------------------------------------*/ /* testatexit.c */ /* Demonstrate the atexit function. */ /*-------------------------------------------------------------------*/ #include #include /*-------------------------------------------------------------------*/ /* Note that one often must use global variables to communicate with functions that are registered to be executed at process exit. */ static int i = 0; /*-------------------------------------------------------------------*/ static void printi(void) /* Print the value of i. */ { printf("At the end of the process, the value of i is %d.\n", i); } /*-------------------------------------------------------------------*/ int main(void) /* Demonstrate the atexit function. */ { /* Register function printi to be executed at process exit. */ atexit(printi); /* Do some computation. */ i = 5; return 0; } /* Example execution: $ gcc -Wall -ansi -pedantic -o testatexit testatexit.c $ testatexit At the end of the process, the value of i is 5. */