cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : C Library : cstdlib (stdlib.h) : exit
 
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forum
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
C Library
cassert (assert.h)
cctype (ctype.h)
cerrno (errno.h)
cfloat (float.h)
climits (limits.h)
clocale (locale.h)
cmath (math.h)
csetjmp (setjmp.h)
csignal (signal.h)
cstdarg (stdarg.h)
cstddef (stddef.h)
cstdio (stdio.h)
cstdlib (stdlib.h)
cstring (string.h)
ctime (time.h)
cstdlib (stdlib.h)
functions:
· abort
· abs
· atexit
· atof
· atoi
· atol
· bsearch
· calloc
· div
· exit
· free
· getenv
· labs
· ldiv
· malloc
· mblen
· mbstowcs
· mbtowc
· qsort
· rand
· realloc
· srand
· strtod
· strtol
· strtoul
· system
· wcstombs
· wctomb
functions (non-standard):
· itoa
macros:
· EXIT_FAILURE
· EXIT_SUCCESS
· MB_CUR_MAX
· NULL
· RAND_MAX
types:
· div_t
· ldiv_t
· size_t

-

exit function
void exit ( int status );
<cstdlib>

Terminate calling process

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

First, all functions registered by calls to atexit are executed in the reverse order of their registration. Then, all streams are closed and the temporary files deleted, and finally the control is returned to the host environment.

The status argument is returned to the host environment.

Parameters

status
Status value returned to the parent process. Generally, a return value of 0 or EXIT_SUCCESS indicates success, and any other value or the constant EXIT_FAILURE is used to indicate an error or some kind of abnormal program termination.

Return Value

(none)

Example

/* exit example */
#include <stdio.h>
#include <stdlib.h>

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

See also

abort Abort current process (function)
atexit Set function to be executed on exit (function)
© The C++ Resources Network, 2000-2007 - All rights reserved
Spotted an error? - contact us