A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cplusplus.com/exit below:

function

<cstdlib>

exit
[[noreturn]] void exit (int status);

Terminate calling process

Terminates the process normally, performing the regular cleanup for terminating programs.

Normal program termination performs the following (in the same order):



Note that objects with automatic storage are not destroyed by calling exit (C++).

If status is zero or EXIT_SUCCESS, a successful termination status is returned to the host environment.


If status is EXIT_FAILURE, an unsuccessful termination status is returned to the host environment.
Otherwise, the status returned depends on the system and library implementation.

For a similar function that does not perform the cleanup described above, see quick_exit.



Parameters
status
Status code.
If this is 0 or EXIT_SUCCESS, it indicates success.
If it is EXIT_FAILURE, it indicates failure.

Return Value none (the function never returns).

Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/* exit example */
#include <stdio.h>      /* printf, fopen */
#include <stdlib.h>     /* exit, EXIT_FAILURE */

int main ()
{
  FILE * pFile;
  pFile = fopen ("myfile.txt","r");
  if (pFile==NULL)
  {
    printf ("Error opening file");
    exit (EXIT_FAILURE);
  }
  else
  {
    /* file operations here */
  }
  return 0;
}

Data races Calling this function destroys all objects with static duration: A program with multiple threads running shall not call exit (see quick_exit for a similar function that does not affect static objects).

Exceptions (C++)No-throw guarantee: this function never throws exceptions.

If the program termination process described above throws an exception, terminate is automatically called.



See also
abort
Abort current process (function)
atexit
Set function to be executed on exit (function)

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4