cpp/utility/program/exit

Causes normal program termination to occur.

Several cleanup steps are performed:


 * In the above,
 * if any function registered with or any destructor of static/thread-local object throws an exception, std is called
 * if the compiler opted to lift dynamic initialization of an object to the static initialization phase of non-local initialization, the sequencing of destruction honors its would-be dynamic initialization.
 * If a function-local (block-scope) static object was destroyed and then that function is called from the destructor of another static object and the control flow passes through the definition of that object (or if it is used indirectly, via pointer or reference), the behavior is undefined.
 * if a function-local (block-scope) static object was initialized during construction of a subobject of a class or array, it is only destroyed after all subobjects of that class or all elements of that array were destroyed.

@2@ all C streams are flushed and closed @3@ files created by std are removed @4@ control is returned to the host environment. If is 0 or exit_success, an implementation-defined status indicating successful termination is returned. If is exit_failure, an implementation-defined status indicating unsuccessful termination is returned. In other cases implementation-defined status value is returned.

Stack is not unwound: destructors of variables with automatic storage duration are not called.

Relationship with the main function
Returning from the main function, either by a statement or by reaching the end of the function performs the normal function termination (calls the destructors of the variables with automatic storage durations) and then executes, passing the argument of the return statement (or  if implicit return was used) as.

Return value
(none)