What is exit in c programming?

exit in c programming causes normal termination of a process. While termination, all files will be closed.

It also raises SIGCHILD signal if child process is created by the current process.

It is defined in stdlib.h header file

Prototype

void exit(int status);

Return value

This function does not returns any value.


Exit in c example program

// C program to illustrate exit function
#include<stdio.h>
#include<stdlib.h>
int main()
{
  printf("This program exiting \n");
  exit(0);
}  

Output

Exit in c program output

Code explanation

exit() causes normal termination of a program.

Read reference of al functions and constants in stdlib.h.


People also ask for

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

exit(0) indicates normal termination. exit(1) indicates some error.