Table of contents
1.
Introduction
2.
quick_exit() function
3.
Syntax
4.
Parameter
5.
Return Value
6.
Example
7.
Frequently Asked Questions
7.1.
What is the Standard Template Library?
7.2.
What is the quick_exit() function?
7.3.
In which header file the quick_exit() function is defined?
7.4.
What is the return value of the quick_exit() function?
8.
Conclusion
Last Updated: Mar 27, 2024

quick_exit() function in C++

Author Nagendra
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

C++ is one of the most extensively utilised programming languages for competitive programming. Learning C++ reinforces essential computer science principles while also providing access to a wide range of professional options. The Standard Template Library is a set of template classes written in C++ that provide common data structures and functions, including lists, stacks, and arrays. It's a container class library with algorithms and iterators. It is a parameterized library since it is a generic library. The article explains about the quick_exit() function.

quick_exit() function

The stdlib header file defines the quick_exit() function. The quick_exit() function is used to terminate a process normally without cleaning up the resources. The functions registered using quick_exit() are called in reverse order of their registration when quick_exit() is called. Terminate() is triggered if any of the registered functions create an unhandled exception.
A call to _Exit(exit code) is performed after all the registered functions have been called.

Also see, Literals in C, Fibonacci Series in C++

Syntax

void quick_exit(int val);

Parameter

This method has only one parameter, val, which is an integral value that represents a program's exit state.

  • If exit_code is 0 or EXIT SUCCESS, the program has been terminated.
  • If the parameter value is non-zero or EXIT FAILURE, the application was not terminated successfully. These functions are called in the reverse order in which they were called.

Return Value

The quick_exit() function had no return value.

Also Read - C++ Interview Questions

Example

Consider the following code snippet :

#include <bits/stdc++.h>
using namespace std;
void func1()
{
    cout << "Inside Function 1" << "\n";
}
void func2()
{
    cout << " Inside Exit Function 2" << "\n";
}
 
int main()
{
    at_quick_exit(func1);
    at_quick_exit(func2);
    quick_exit(0);
    return 0;
}
You can also try this code with Online C++ Compiler
Run Code

Output:

Inside Exit Function 2
Inside Exit Function 1
You can also try this code with Online C++ Compiler
Run Code

Explanation :

In the above code snippet, the func1 was first registered with the quick_exit() function, but the output displays that func2 is called first, which shows that quick_exit() functions are called in the reverse order in which they were called.

Try and compile with online c++ compiler.

Must Read Dynamic Binding in C++

Frequently Asked Questions

What is the Standard Template Library?

The Standard Template Library is a set of template classes written in C++. that provide common data structures and functions, including lists, stacks, and arrays.

What is the quick_exit() function?

The quick_exit() function is used to terminate a process normally without cleaning up the resources.

In which header file the quick_exit() function is defined?

The stdlib header file defines the quick_exit() function.

What is the return value of the quick_exit() function?

The quick_exit() function had no return value.

Conclusion

In this article, we have extensively discussed the quick_exit() function in C++. The article explains the details of the quick_exit() function in C++.
We hope that this blog has helped you enhance your knowledge regarding the quick_exit() function in C++ and if you would like to learn more, check out our articles on C++. You can refer to our guided paths on the Coding Ninjas Studio platform to learn more about DSA, DBMS, Competitive Programming, Python, Java, JavaScript, etc. To practice and improve yourself in the interview, you can also check out Top 100 SQL problemsInterview experienceCoding interview questions, and the Ultimate guide path for interviews.
Do upvote our blog to help other ninjas grow. 

Happy Coding!!

Live masterclass