atexit() function in C/C++ Last Updated : 04 Feb, 2021 Comments Improve Suggest changes Like Article Like Report The function pointed by atexit() is automatically called without arguments when the program terminates normally. In case more than one function has been specified by different calls to the atexit() function, all are executed in the order of a stack (i.e. the last function specified is the first to be executed at exit). A single function can be registered to be executed at exit more than once. Syntax : extern "C" int atexit (void (*func)(void)) noexcept; extern "C++" int atexit (void (*func)(void)) noexcept Note: extern refers that the name will refer, to the same object in the entire program .Parameters : The function accepts a single mandatory parameter func which specifies the pointer to the function to be called on normal program termination(Function to be called). Return Value : The function returns following values: Zero, if the function registration is successfulNon zero, if the function registration failed Below programs illustrate the above-mentioned function:Program 1: CPP // C++ program to illustrate // atexit() function #include <bits/stdc++.h> using namespace std; // Returns no value, and takes nothing as a parameter void done() { cout << "Exiting Successfully" << "\n"; // Executed second } // Driver Code int main() { int value; value = atexit(done); if (value != 0) { cout << "atexit () function registration failed"; exit(1); } cout << " Registration successful" << "\n"; // Executed First return 0; } Output: Registration successful Exiting Successfully If atexit function is called more than once, then all the specified functions will be executed in a reverse manner, same as of the functioning of the stack. Program 2: CPP // C++ program to illustrate // more than one atexit function #include <bits/stdc++.h> using namespace std; // Executed last, in a Reverse manner void first() { cout << "Exit first" << endl; } // Executed third void second() { cout << "Exit Second" << endl; } // Executed Second void third() { cout << "Exit Third" << endl; } // Executed first void fourth() { cout << "Exit Fourth" << endl; } // Driver Code int main() { int value1, value2, value3, value4; value1 = atexit(first); value2 = atexit(second); value3 = atexit(third); value4 = atexit(fourth); if ((value1 != 0) or (value2 != 0) or (value3 != 0) or (value4 != 0)) { cout << "atexit() function registration Failed" << endl; exit(1); } // Executed at the starting cout << "Registration successful" << endl; return 0; } Output: Registration successful Exit Fourth Exit Third Exit Second Exit first Program 3 : CPP // C++ program to illustrate // atexit() function when it throws an exception. #include <bits/stdc++.h> using namespace std; void shows_Exception() { int y = 50, z = 0; // Program will terminate here int x = y / z; // Cannot get printed as the program // has terminated cout << "Divided by zero"; } // Driver Code int main() { int value; value = atexit(shows_Exception); if (value != 0) { cout << "atexit() function registration failed"; exit(1); } // Executed at the starting cout << "Registration successful" << endl; return 0; } Note: If a registered function throws an exception which cannot be handled, then the terminate() function is called. Comment More infoAdvertise with us Next Article atexit() function in C/C++ A AmanSrivastava1 Follow Improve Article Tags : Misc C Language C++ CPP-Functions C-Library +1 More Practice Tags : CPPMisc Similar Reads atoi() Function in C In C, atoi stands for ASCII To Integer. The atoi() is a library function in C that converts the numbers in string form to their integer value. To put it simply, the atoi() function accepts a string (which represents an integer) as a parameter and yields an integer value in return. C atoi() function 6 min read asctime() function in C++ The asctime() function is defined in the ctime header file. The asctime() function converts the given calendar time of structure tm to a character representation i.e human readable form. Syntax: char* asctime(const struct tm * time_ptr); Parameter: This function accepts single parameter time_ptr i.e 1 min read acos() function in C++ STL acos() is an inbuilt function in C++ STL and itâs the same as the inverse of cosine in maths. The acos() function returns the values in the range of [0, Ï] which is the angle in radians. Syntaxacos(data_type x);ParametersThis function accepts one mandatory parameter x which specifies the value whose 3 min read clock() function in C The clock() function in C returns the approximate processor time that is consumed by the program which is the number of clock ticks used by the program since the program started. The clock() time depends upon how the operating system allocates resources to the process that's why clock() time may be 2 min read atanh() function in C++ STL The atanh() is an inbuilt function in C++ STL that returns the inverse hyperbolic tangent of an angle given in radians. The function belongs to <cmath> header file.Syntax:Â atanh(data_type x) Parameter: This function accepts one mandatory parameter x which specifies the inverse hyperbolic angl 3 min read fmod() Function in C The fmod() function in C computes the floating-point remainder of the division of two numbers. It is part of the math library <math.h> in C and <cmath> in C++.fmod() in CThe fmod() function returns the remainder of the division of two floating-point numbers. It is particularly useful whe 3 min read c16rtomb() function in C/C++ The c16rtomb() is a built-in function in C/C++ which converts 16 bit character representation to a narrow multibyte character representation. It is defined within the uchar.h header file of C++. Syntax: size_t c16rtomb(char* s, char16_t c16, mbstate_t* p) Parameters: The function accepts three manda 2 min read c32rtomb() function in C/C++ The c32rtomb() is a built-in function in C/C++ which converts 32 bit character representation to a narrow multibyte character representation. It is defined within the uchar.h header file of C++. Syntax: size_t c32rtomb(char* s, char32_t c32, mbstate_t* p) Parameters: The function accepts three manda 2 min read strtod() function in C/C++ The strtod() is a builtin function in C and C++ STL which interprets the contents of the string as a floating point number and return its value as a double. It sets a pointer to point to the first character after the last valid character of the string, only if there is any, otherwise it sets the poi 4 min read std::function in C++ The std::function() in C++ is a function wrapper class which can store and call any function or a callable object. In this article, we will learn about std::function in C++ and how to use it in different cases.Table of ContentWhat is std::function in C++?Example of std::functionMember Functions of s 5 min read Like