English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C / C ++exit() in

Exit()

This functionexit();Used to terminate the calling function immediately without performing further processing. Asexit();The function call terminates the process. It only calls the constructor of the class. It is declared in the 'stdlib.h' header file of C language. It does not return anything.

The following is the syntax exit();

void exit(int status_value);

Here,

status_value-The value returned to the parent process.

The following is an example exit();

Example

#include <stdio.h>
#include <stdlib.h>
int main() {
   int x = 10;
   printf("The value of x : %d\n", x);
   exit(0);
   printf("Calling of exit()");
   return 0;
}

Output result

The value of x : 10

In the above program, the variable 'x' is initialized with a value. Print the value of the variable andexit();Calling the function. Asexit();stated, it exits immediately and does not print the statements insideprintf();callexit();As follows-

int x = 10;
printf("The value of x : %d\n", x);
exit(0);

_Exit()

The function _Exit() is used to terminate the process normally and return control to the host environment. It does not perform any cleanup tasks.

The following is the syntax of _Exit()

void _Exit(int status_value);

Here,

status_value-The value returned to the parent process.

The following is an example of _Exit()

Example

#include <stdio.h>
#include <stdlib.h>
int main() {
   int x = 10;
   printf("The value of x : %d\n", x);
   _Exit(0);
   printf("Calling _Exit()");
   return 0;
}

In the above program, it will neither display any content nor show any errors.