atexit - C stdlib.h

C examples for stdlib.h:atexit

Type

function

From


<cstdlib>
<stdlib.h>

Description

Set function to be executed on exit

Prototype

int atexit (void (*func)(void)) noexcept;
int atexit (void (*func)(void));

Parameters

Parameter Description
function Function to be called. The function should return no value and take no arguments.

Return Value

On success, a zero value is returned.

On error, a non-zero value is returned.

Demo Code


#include <stdio.h>
#include <stdlib.h>

void fnExit1 (void){
  puts ("Exit function 1.");
}

void fnExit2 (void){
  puts ("Exit function 2.");
}

int main ()/*w  w  w  . j  a va 2s. c o  m*/
{
  atexit (fnExit1);

  atexit (fnExit2);

  puts ("Main function.");

  return 0;
}

Related Tutorials