Professional Documents
Culture Documents
BASIS FOR
EXIT(0) EXIT(1)
COMPARISON
program.
in between because of
the error.
Definition of exit(0)
The function exit(0) is a jump statement of C++. It is used to terminate the
program or let the control exit out of the program. It reports the operating
system about the successful termination of the program which indicates to
the operating system that the task of the program has been successfully
completed.
The macro used for return code “0” is “EXIT_SUCCESS”, so, you can use it in
a way exit(EXIT_SUCCESS). The general form of the exit(0) function is:-
Here, the formal parameter “return_code” is the value that is returned to the
calling function. The returen_code is always of integer type as the value
returned to the calling function will either be zero or a non-zero value. The
exit(0) is a standard library function, if we are using exit(0) in the program
we have to use the header file <cstdlib.h>.
Definition of exit(1)
The function exit(1) is also a jump statement of C++. The exit(1) also
terminates the program but, abnormally. The exit(1) reports the operating
system that the program is not successfully executed, or it is aborted in
between the execution due to some or the other error. The exit(1) function
is defined in the standard library function, in case you are using exit(1) in
your program you have to specifically mention the header file <cstdlib.h> at
the top of the program.
The macro for return code “1” is “EXIT_FAILURE”, so, it can be written in a
way “exit(EXIT_FAILURE)”.
as the stack is empty then we return exit(1). It indicates that the task of the
pop function has not been completed. Hence, the execution is terminated
abnormally.
Note
If the exit( ) function does not return anything, it means it does not want to
reveal the status of the termination of the program to the operating system.
Conclusion
To report the status of the termination of the program, one uses an exit( )
function. An exit(0) reveal to the operating system that the task of the
program has been successfully completed. An exit(1) reveals that the task of
the program is not completed, and the program execution is aborted
abnormally.