(m)
exit(0)
This causes the program to exit with a successful termination.
exit(1)
This causes the program to exit with a system-specific meaning.
On many systems, exit(1) signals some sort of failure, however there
is no guarantee.
As I recall, the C standard only recognizes three standard exit
values:
EXIT_SUCCESS -- successful termination
EXIT_FAILURE -- unsuccessful termination
0 -- same as EXIT_SUCCESS
Now, as to what happens after the program exits, is beyond the scope of the C standard.
2006-11-01 20:28:55
·
answer #1
·
answered by mallimalar_2000 7
·
5⤊
0⤋
Hi!
My answer is little different from others:
When you compile your program the compiler just compiles the program and then gives the object codes to the operating system to run it like in windows if you are writing your program with the help of turbo c (dos based) then you see a black screen for the out put. That black screen is actually the environment provided by dos to run the program.
Now what does exit function do? It returns the control to the operating system telling the operating system that whether the program is terminated normally or abnormally.
Whenever a program encounters the instruction
exit(0);
it means it sent a 0 to operating system which means normal termination of the program and same is entered in the system log
and
Whenever a program encounters the instruction
exit(1);
it means it sent a 1 to operating system which means abnormal termination and it enters an error termination in the system log.
However you can send any number to the operating system in place of 1 and 0. System has its own mechanism to evaluate all the numbers and accordingly it will enter the reports in the system log.
Hope this should satisfy your need.
2006-11-01 23:31:46
·
answer #2
·
answered by Mani_0007 1
·
1⤊
0⤋
When we write a (C) program we are usually interested in finding out if the program has executed successfully or not, and in case the program has failed: what is the reason for the failure?
The exit() function is used to convey this information to the Operating System or the parent program that invokes the specified program.
Lets assume that you have written a hypothetical program called 'word count' that counts the number of words in a file and prints the result on screen.
When the program works file, the output is something like this:
% wordcount somefile.txt
123 words
% echo $?
0
Note that "$?" is a special variable in UNIX that displays the value of the exit status of a program.
However there could be many situations where the program might not be able to perform it's role, like a non-existant file or encountering a problem in doing File IO. In such cases, we want to know why the program has failed, and this can be gleaned from the exit value of a program. Eg:
% wordcount non-existant-file.txt
% echo $?
1
% wordcount fileio-error.txt
% echo $?
2
The reason why '0' is chosen for success is pretty simple. This can help in making boolean checks for checking the status of an invoked program. E.g
int exit_val = exec("wordcount", "somefile.txt");
if( !exit_val ) {
print("Program run successfully");
}
else {
// We can use the exit value to find out what's the issue
switch(exit_val) {
case 1: print("Non existant file specified"); break;
case 2: print("File IO error"); break;
}
2006-11-03 12:32:18
·
answer #3
·
answered by swami060 3
·
0⤊
0⤋
In exit(0) and exit(1), the 0 and 1 are the status that the program return to the operating system. To implement exit() function u need to include process.h file, its better u open the header file and see what the corresponding numbers are meant for. May be u find some other status too.
2006-11-02 01:18:16
·
answer #4
·
answered by Napster 2
·
0⤊
0⤋
exit(0) returns 0 to the calling function
exit(1) returns 1 to the calling function
you can have even exit(anynumber), nothing but the number is returned to the caller function.
Conventiaonlly, 0 is used for successful completion and 1 is returned for erroreous completion.
any unix function returns 0 for successful completion and 1 for unsuccess.
But if you are writing, though its good to follow the convention, you can have any number to return as long as you are using the function and you remember everyitime whats the return number and what its status meaning.
2006-11-01 21:34:00
·
answer #5
·
answered by test 3
·
0⤊
0⤋
System.exit 1
2016-11-12 22:09:43
·
answer #6
·
answered by ? 4
·
0⤊
0⤋
0 is normal exit whereas 1 is abnormal termination
2006-11-01 19:59:21
·
answer #7
·
answered by Demo 3
·
1⤊
0⤋
exit(0) is a graceful exit while exit(1) is not.
2006-11-01 19:58:21
·
answer #8
·
answered by Vaibhav 4
·
1⤊
0⤋
the convention is that exit(0) means that the program completed successfully, while exit(1) means it didn't
2006-11-01 20:14:06
·
answer #9
·
answered by Deep Thought 5
·
1⤊
0⤋
exit(0) --> 0 marks
exit(1) --> 1 marks
2006-11-01 19:59:02
·
answer #10
·
answered by lakshmi r 4
·
0⤊
0⤋