What is abort in c Programming?

abort function in c abnormally terminates the program. This function may not closes the files that are opened by the currently executing the program.

It raises SIGABRT signal to terminate the process.

It indicates the unsuccessful termination of a program.

This function is defined in stdlib.h header file.

Prototype

void abort(void);

Return value

This function does not returns any value.


Example Program for abort()

#include<stdio.h>
#include<stdlib.h>
int main()
{
  int a,b;
  printf("enter the values of a and b in (a/b) format \n");
  scanf("%d,%d",&a,&b);
  if(b==0)
  {
    printf("denominator cannot be zero \n");
    abort();
  }
  res=a/b;
  printf("The result is %d\n",res);
  return 0;
}

Output

enter the values of a and b in (a/b) format 

10

0


denominator cannot be zero
abort function in c output
abort function in c output

Code Explanation

abort() terminates the program immediately if it finds that denominator value is zero.


People Also Ask for

What causes abnormal termination of a program?

The abort function terminates the program abnormally.

What is abnormal program termination?

In abnormal program termination, the abort function does not return any value to the main function.