top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is the difference between exit(0) and exit(1) in C language?

0 votes
1,340 views
What is the difference between exit(0) and exit(1) in C language?
posted Jun 19, 2014 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

0 votes

In C we have two predefined values i.e. EXIT_SUCCESS and EXIT_FAILURE to return termination status which are defined as 0 and 1.

So when we say exit(0) it means successful completion of the program and when we say exit(1) then it means unsuccessful termination.

Example see the following program if you press the ctrl+c i.e. SIGINT then it returns the 1 which can be caught in the shell in case of normal termination it returns zero.

signal_proc()
{
  printf("Normal Termination");
  exit(1);  // Abnormal Termination
}

main()
{
  int i;
  signal(SIGINT,signal_proc);
  for(i=0; i<10000000; i++)
  ;
  printf("Normal Termination");
  exit(0)
}
answer Jun 19, 2014 by Salil Agrawal
nice explanation
0 votes

exit(0) Means terminate program normally & exit(1) Means there are errors in termination

answer Sep 5, 2016 by Sharad Gangurde
...