The function atexit () in C

Int atexit function (void (* func) (void)) calls function func when the program ends. You can register your end function (func function) wherever you like, but this function will be called at the end of the program.

Int atexit function (void (* func) (void)) calls function func when the program ends. You can register your end function (func function) wherever you like, but this function will be called at the end of the program.

Declare the function atexit () in C

Below is the declaration for atexit () in C:

 int atexit ( void (* func )( void )) 

Parameters

func : This is the function to be called at the end of the program.

Returns the value

This function returns a value of 0 if this function is successfully registered. If it fails, it returns a value other than 0.

For example

The following program C illustrates the usage of atexit () in C:

 #include #include void functionA () { printf ( "Vi du mot ham functionAn" ); } int main () { /* Dang ky mot ham ket thuc chuong trinh */ atexit ( functionA ); printf ( "Bat dau chay phan chuong trinh chinh .n" ); printf ( "Thoat chuong trinh chinh .n" ); return ( 0 ); } 

Compiling and running the above C program will result:

Picture 1 of The function atexit () in C

According to Tutorialspoint

Previous lesson: Abort () function in C

Next lesson: Function exit () in C

Update 25 May 2019
Category

System

Mac OS X

Hardware

Game

Tech info

Technology

Science

Life

Application

Electric

Program

Mobile