Home »
C++ programming language
at_quick_exit() Function with Example in C++
C++ at_quick_exit() function: Here, we are going to learn about the at_quick_exit() function with example of cstdlib header in C++ programming language.
Submitted by IncludeHelp, on May 28, 2020
C++ at_quick_exit() function
at_quick_exit() function is a library function of cstdlib header. It is used to set a function that should be executed on quick exit. Sometimes we need to write such code (like freeing the memory occupied by the global variables, closing the file objects, etc) that should be executed when the quick exit, any user-defined can be written for it and that can be set as a quick exit function using using at_quick_exit() function.
Syntax
Syntax of at_quick_exit() function:
C++11:
extern "C" int at_quick_exit (void (*func)(void)) noexcept;
extern "C++" int at_quick_exit (void (*func)(void)) noexcept;
Parameter(s)
- func – represents the function to be called on quick exit.
Return value
The return type of this function is int, it returns 0 if the function registered successfully; non-zero, otherwise.
Sample Input and Output
// defining the function
void function_name(void){
// function code
}
// setting the function
at_quick_exit(function_name);
Example
C++ code to demonstrate the example of at_quick_exit() function:
// C++ code to demonstrate the example of
// at_quick_exit() function
#include <iostream>
#include <cstdlib>
using namespace std;
void myfunc(void)
{
cout << "Bye, Bye..." << endl;
}
// main() section
int main()
{
//setting the functions
at_quick_exit(myfunc);
cout << "Hi, friends..." << endl;
cout << "Input first number: ";
int a;
cin >> a;
cout << "Input second number: ";
int b;
cin >> b;
cout << a << "+" << b << " = " << a + b << endl;
//quick exit
quick_exit(EXIT_SUCCESS);
cout << "End of the main()..." << endl;
return 0;
}
Output
Hi, friends...
Input first number: 10
Input second number: 20
10+20 = 30
Bye, Bye...
Reference: C++ at_quick_exit() function