The exit () function in C

The void exit (int status) function immediately terminates the calling process. Any file opened by the process is closed and any child process is inherited by the initial process and the parent process is sent a SIGCHILD signal.

The void exit (int status) function immediately terminates the calling process. Any file opened by the process is closed and any child process is inherited by the initial process and the parent process is sent a SIGCHILD signal.

Declare the exit () function in C

Below is the declaration for exit () in C:

 void exit ( int status ) 

Parameters

status : This is the status value returned to the parent process.

Returns the value

This function does not return any values.

For example

The following C program illustrates the usage of exit () in C:

 #include #include int main () { printf ( "Bat dau thuc thi chuong trinh .n" ); printf ( "Thoat chuong trinh .n" ); exit ( 0 ); printf ( "Ket thuc chuong trinh .n" ); return ( 0 ); } 

Compiling and running the above C program will result:

The exit () function in C Picture 1The exit () function in C Picture 1

According to Tutorialspoint

Previous article: Function atexit () in C

Next lesson: Function getenv () in C

5 ★ | 1 Vote