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:
According to Tutorialspoint
Previous lesson: Abort () function in C
Next lesson: Function exit () in C
You've just finished reading the article "The function atexit () in C" edited by the TipsMake team. You can save the-function-atexit-in-c.pdf to your computer here to read later or print it out. We hope this article has provided you with many useful tech tips and tricks. You can search for similar articles on tips and guides. Thank you for reading and for following us regularly.