C quick_exit() Function

Beginner
7 min read
Updated: Nov 2026
3 examples
<stdlib.h>

Definition

The C quick_exit() function performs quick program termination. Registered quick-exit callbacks run in reverse registration order. The function then returns control to the host without normal exit cleanup.

This function is declared in <stdlib.h>. Its contract matters as much as its call: validate every required precondition, check any documented sentinel, and keep ownership or host effects clear in the surrounding code. There is no success return; EXIT_SUCCESS reports a successful result to the host. There is no failure return; EXIT_FAILURE reports an unsuccessful result. The examples below move from the direct call to an edge condition and a practical use.

Syntax

Start with this concrete quick_exit() call:

C
quick_exit(EXIT_SUCCESS);
CallWhat it does
quick_exit(EXIT_SUCCESS);Performs quick program termination using the concrete values shown.

Include <stdlib.h>. Also include headers that declare any types, limits, locale tools, or I/O functions used around the call.

Library declaration
C
void quick_exit(int status);

Parameters

ParameterDescription
statusTermination status communicated to the host.

Return Value

Return ValueDescription
Does not returnQuick termination begins.

C Examples

Example 1 — Terminate with success

This complete program demonstrates a distinct part of the quick_exit() contract and checks the result or precondition that matters for the scenario.

C
#include <stdio.h>
#include <stdlib.h>
int main(void){puts("work complete");fflush(stdout);quick_exit(EXIT_SUCCESS);}

How It Works

  1. Step 1. Finish the demonstration work.
  2. Step 2. Flush stdout explicitly so every termination style displays it.
  3. Step 3. Call quick_exit() with EXIT_SUCCESS.
  4. Step 4. Control does not return to main.

Example 2 — Terminate with failure

This complete program demonstrates a distinct part of the quick_exit() contract and checks the result or precondition that matters for the scenario.

C
#include <stdio.h>
#include <stdlib.h>
int main(void){fputs("operation failed\n",stderr);quick_exit(EXIT_FAILURE);}

How It Works

  1. Step 1. Detect or simulate an unrecoverable program result.
  2. Step 2. Write the explanation to stderr.
  3. Step 3. Pass EXIT_FAILURE to quick_exit().
  4. Step 4. The host receives an unsuccessful termination status.

Example 3 — Observe the cleanup policy

This complete program demonstrates a distinct part of the quick_exit() contract and checks the result or precondition that matters for the scenario.

C
#include <stdio.h>
#include <stdlib.h>
static void done(void){fputs("handler ran\n",stderr);fflush(stderr);}
int main(void){at_quick_exit(done);fputs("terminating\n",stderr);fflush(stderr);quick_exit(EXIT_SUCCESS);}

How It Works

  1. Step 1. Register a matching handler.
  2. Step 2. Print the pre-termination line to stderr and flush it.
  3. Step 3. Invoke quick_exit().
  4. Step 4. The matching callback runs before termination.

Frequently Asked Questions

quick_exit() performs quick program termination. Registered quick-exit callbacks run in reverse registration order. The function then returns control to the host without normal exit cleanup.
Include <stdlib.h> before calling quick_exit().
There is no success return; EXIT_SUCCESS reports a successful result to the host. There is no failure return; EXIT_FAILURE reports an unsuccessful result.
Only at_quick_exit handlers are called. atexit handlers do not run, and stream flushing is not guaranteed.
The function is specified by the C standard library. Exact limits, locale behavior, environment behavior, allocation capacity, or host effects can still vary where relevant.

Next: rand()

Continue through the C stdlib.h tutorials.

rand() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful