The C abort() function terminates the program abnormally. It raises SIGABRT. A signal handler may intercept the signal, but if the signal is not caught or is ignored, termination proceeds as defined by the implementation.
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 value because abort() never returns to its caller. Failure is not reported with a return value; abort() initiates abnormal termination. The examples below move from the direct call to an edge condition and a practical use.
Syntax
Start with this concrete abort() call:
C
abort();
Call
What it does
abort();
Terminates the program abnormally 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 abort(void);
Parameters
Parameter
Description
None
abort() takes no parameters.
Return Value
Return Value
Description
Does not return
Abnormal termination is initiated by raising SIGABRT.
C Examples
Example 1 — Report before aborting
This complete program demonstrates a distinct part of the abort() contract and checks the result or precondition that matters for the scenario.
C
#include <stdio.h>
#include <stdlib.h>
int main(void){fputs("fatal input\n",stderr);abort();}
Output
fatal input
then abnormal termination
How It Works
Step 1. Write diagnostic text to stderr.
Step 2. Call abort() for an unrecoverable condition.
Step 3. SIGABRT is raised.
Step 4. The function never reaches a normal return.
Example 2 — Show that later code is unreachable
This complete program demonstrates a distinct part of the abort() contract and checks the result or precondition that matters for the scenario.
C
#include <stdio.h>
#include <stdlib.h>
int main(void){puts("before");fflush(stdout);abort();puts("after");}
Output
before
then abnormal termination
How It Works
Step 1. Print the line that precedes termination.
Step 2. Flush explicitly so the demonstration is visible.
Step 3. abort() initiates abnormal termination.
Step 4. The later puts() call is unreachable.
Example 3 — Contrast with atexit
This complete program demonstrates a distinct part of the abort() contract and checks the result or precondition that matters for the scenario.
C
#include <stdio.h>
#include <stdlib.h>
static void done(void){puts("atexit cleanup");}
int main(void){atexit(done);fputs("aborting\n",stderr);abort();}
Output
aborting
(atexit cleanup does not run)
How It Works
Step 1. Register a normal-exit callback.
Step 2. Emit a diagnostic before failure.
Step 3. abort() takes the abnormal path.
Step 4. Normal atexit processing is bypassed.
Frequently Asked Questions
abort() terminates the program abnormally. It raises SIGABRT. A signal handler may intercept the signal, but if the signal is not caught or is ignored, termination proceeds as defined by the implementation.
Include <stdlib.h> before calling abort().
There is no success return value because abort() never returns to its caller. Failure is not reported with a return value; abort() initiates abnormal termination.
abort() does not run functions registered with atexit(). Open streams are not guaranteed to be flushed, so it is not a substitute for orderly error handling.
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.