Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

C Library Function - abort()

C Library Function - abort()

C Standard Library - <stdlib.h> C Standard Library -

C library function void abort(void) terminates program execution, jumping directly out from the point of call.

abort The function is part of the C standard library and is used to immediately terminate the current program. It causes abnormal program termination and produces a core dump file (if the system configuration allows). This function is defined in header.

Syntax

void abort(void);

Parameters

abort The function takes no arguments.

Return Value

abort The function has no return value because it does not return normally.

Example

The following is an example of using abort An example program for the function. The program calls abort to terminate the program.

Example

#include

#include

int

main

(

)

{

   

printf

(

"Starting program...\n"

)

;

   

// Simulate detection of an error condition

   

if

(

1

)

{

       

printf

(

"Error detected, aborting program...\n"

)

;

       

abort

(

)

;

   

}

   

// This line of code will not be executed

   

printf

(

"This line will not be printed.\n"

)

;

   

return

0

;

}

After compiling and running the program, the output will be:



Starting program...

Error detected, aborting program...

After the program detects an error condition, it calls abort to terminate the program, so the last line of code is not executed.

Explanation

Notes

C Standard Library - <stdlib.h> C Standard Library -