
- The C Standard Library
- C Library - Home
- C Library - <assert.h>
- C Library - <ctype.h>
- C Library - <errno.h>
- C Library - <float.h>
- C Library - <limits.h>
- C Library - <locale.h>
- C Library - <math.h>
- C Library - <setjmp.h>
- C Library - <signal.h>
- C Library - <stdarg.h>
- C Library - <stddef.h>
- C Library - <stdio.h>
- C Library - <stdlib.h>
- C Library - <string.h>
- C Library - <time.h>
- C Standard Library Resources
- C Library - Quick Guide
- C Library - Useful Resources
- C Library - Discussion
- C Programming Resources
- C Programming - Tutorial
- C - Useful Resources
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C library function - atexit()
Description
The C library function int atexit(void (*func)(void)) causes the specified function func to be called when the program terminates. You can register your termination function anywhere you like, but it will be called at the time of the program termination.
Declaration
Following is the declaration for atexit() function.
int atexit(void (*func)(void))
Parameters
func − This is the function to be called at the termination of the program.
Return Value
This function returns a zero value if the function is registered successfully, otherwise a non-zero value is returned if it is failed.
Example
The following example shows the usage of atexit() function.
#include <stdio.h> #include <stdlib.h> void functionA () { printf("This is functionA\n"); } int main () { /* register the termination function */ atexit(functionA ); printf("Starting main program...\n"); printf("Exiting main program...\n"); return(0); }
Let us compile and run the above program that will produce the following result −
Starting main program... Exiting main program... This is functionA
stdlib_h.htm
Advertisements