+ 1

Exit();

Hello! Could someone please explain what's the difference between exit(0); / exit(1); / exit(2); ? Thank u!!

29th Jan 2019, 9:42 PM
MargaritaK
3 Respuestas
+ 7
It's basically like the return value from main. The parent process can use that value, 0 meaning no error and another value meaning whatever you want.
29th Jan 2019, 10:46 PM
Zen
Zen - avatar
+ 3
That return value is got by the application which calls your c program. The standard meaning of zero is program finished without errors. You have to give a special meaning to the rest of values (1,2,3 ...) related to your program possible errors and describe it in your program documentation. This is useful when calling your program from a script which checks return value errors in order to continue executing the script or stop if there are errors
30th Jan 2019, 8:25 PM
Javier Felipe Toribio
Javier Felipe Toribio - avatar
+ 2
Just to add to Zen explanation, everything return will not necessarily be considered an error, in fact the shell only keeps one byte so if you write a multiple of 256 (0 included), you will see 0 as the returned value. Be careful of that if you use the return value of a program. I do not know if there is a way to prevent this behavior, I should test it but I can't right now ^^
30th Jan 2019, 1:13 PM
Baptiste E. Prunier
Baptiste E. Prunier - avatar