quick_exit() function in C++ with Examples


In this article we will be discussing the working, syntax and examples of quick_exit() function in C++ STL.

What is quick_exit()?

quick_exit() function is an inbuilt function in C++ STL, which is defined in the <cstdlib> header file. quick_exit() function is used to quickly terminate the calling process means it terminates the process without cleaning of its resources.

This function is used for normal termination and no additional cleanup tasks are being performed like, no object destructors are called, whereas the C streams are closed or flushed, the files which are opened with tmpfile are being removed.

When we terminate a process using quick_exit() then a status is returned to the host environment,

  • If the status is zero or EXIT_SUCCESS, means the termination was successful
  • If the status is EXIT_FAILURE , means the termination was not successful or unsuccessful.

Syntax

void quick_exit( int status );

Parameters

The function accepts following parameter(s) −

  • status − It is the termination status if 0 or EXIT_SUCCESS then termination was successful else if it is EXIT_FAILURE then the termination was unsuccessful.

Return value

This function returns nothing

Example

Input

printf(“Before exit”);
quick_exit(EXIT_SUCCESS);
printf(“After Exit”);

Output

Before exit

Example

 Live Demo

#include <bits/stdc++.h>
using namespace std;
void exit_func1(){
   cout << "This is exit function 1" << endl;
}
void exit_func2(){
   cout << "This is exit function 2" << endl;
}
void exit_func3(){
   cout << "This is exit function 3" << endl;
}
void exit_func4(){
   cout << "This is exit function 4" << endl;
}
int main(){
   at_quick_exit(exit_func1);
   at_quick_exit(exit_func2);
   at_quick_exit(exit_func3);
   at_quick_exit(exit_func4);
   quick_exit(0);
   return 0;
}

Output

This is exit function 4
This is exit function 3
This is exit function 2
This is exit function 1

Updated on: 17-Apr-2020

117 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements