C atexit() function
C atexit() function - Processes the specified function at exit
Syntax atexit() function
int atexit(void (*func)(void))
The atexit() function is used to register the function pointed to by func, to be called without arguments at normal program termination.
Parameters atexit() function
Name | Description | Required /Optional |
---|---|---|
func | Function to be called. | Required |
Return value from atexit()
- Upon successful completion, atexit() shall return 0.
- Otherwise, it shall return a non-zero value.
Example: atexit() function
The following example shows the usage of atexit() function.
#include <stdlib.h>
#include <stdio.h>
void test1(void), test2(void), test3(void), test4(void);
int main( void )
{
atexit(test1);
atexit(test2);
atexit(test3);
atexit(test4);
printf("From Main function....!\n");
}
void test1()
{
printf( "Function1 \n" );
}
void test2()
{
printf( "Function2 \n" );
}
void test3()
{
printf( "Function3 \n" );
}
void test4()
{
printf( "Function4 \n" );
}
Output:
From Main function....! Function4 Function3 Function2 Function1
C Programming Code Editor:
Previous C Programming: C abort()
Next C Programming: C exit()
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/c-programming/stdlib/c-atexit.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics