You are on page 1of 3

Comparison chart

BASIS FOR
EXIT(0) EXIT(1)
COMPARISON

Basic Reports the operating system Reports the operating

about the "successful/normal" system about the

termination/completion of the "abnormal"

program. termination of the

program.

Syntax exit(0); exit(1);

Indicates It indicates that the task has It indicates that the

been successfully performed. task has been aborted

in between because of

the error.

Macros EXIT_SUCCESS EXIT_FAILURE

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:-

1. void exit(int return_code);

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.

Key Differences Between exit(0) and exit(1)


1. The only return_code that indicate the successful termination of the
program is “0”. For reporting abnormal termination of the program, we
can use any value other than “0” i.e. we can use “1”, “2”, “3”… that
means a nonzero value indicates abnormal termination of the program.
2. A Macro can also be used instead of the return_code. Like, in place “0”
you can use “EXIT_SUCCESS” whereas in place of “1” you can use
“EXIT_FAILURE”.
Similarity

1. Both exit(0) and exit(1), are the jump statements of C++.


2. Both exit(0) and exit(1), are used to terminate the program.
3. Both exit(0) and exit(1), are definedunder the header file<cstdlib.h>.
4. Both exit(0) and exit(1), report the status of termination of the
program to the operating system.

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.

You might also like