int  atexit ( void (* function) (void) );

Specifies a function to be executed at exit.
  The function pointed by function parameter is called when the program terminates normally.
  If more than one atexit function is specified calling this, they are all executed in reverse order, that is, the last function specified is the first to be executed at exit.
  ANSI standard specifies that up to 32 functions can be prefixed for a single process.
  These functions will not receive any parameter when called.


Function to be called.

Return Value.
  0 is returned if successful, or a non-zero value if an error occurs.

  Defined in ANSI-C.


/* atexit example */
#include <stdio.h>
#include <stdlib.h>

void fnExit1 (void)
  printf ("Exit function 1.\n");

void fnExit2 (void)
  printf ("Exit function 2.\n");

main ()
  atexit (fnExit1);
  atexit (fnExit2);
  printf ("Main function.\n");
  return 0;
Main function.
Exit function 2.
Exit function 1.

See also.
  exit, abort

© The C++ Resources Network, 2000