C++ quick_exit()

The quick_exit() function in C++ causes normal termination of a process without completely cleaning the resources.

When quick_exit() is called, the functions registered using at_quick_exit() are called in reverse order of their registration. If any unhandled exception are caused by any of the registered functions, terminate() is called.

After calling all the registered functions, a call to _Exit(exit_code) is made.

quick_exit() Prototype

void quick_exit(int exit_code);

The function is defined in <cstdlib> header file.

quick_exit() Parameters

exit_code: An integer value representing the exit status of the program.

  • If exit_code is zero or EXIT_SUCCESS, it indicates successful termination.
  • If exit_code is non-zero or EXIT_FAILURE, it indicates failure.

quick_exit() Return value

The quick_exit() function returns nothing.


Example : How quick_exit() function works?

#include <iostream>
#include <cstdlib>
using namespace std;

void quick_exit1()
{
	cout << "Exit Function 1" << endl;
}
void quick_exit2()
{
	cout << "Exit Function 2" << endl;
}

int main()
{
	/* registering function */
	at_quick_exit(quick_exit1);
	at_quick_exit(quick_exit2);

	quick_exit(0);
	return 0;
}

When you run the program, the output will be:

Exit Function 2
Exit Function 1