Is there any difference between exit(0) & exit(1) ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Is there any difference between exit(0) & exit(1) ?

I often used exit(0) to exit from program .what's exit(1) & it's use??

14th Sep 2016, 6:07 PM
naveen raj
naveen raj - avatar
3 Answers
+ 4
You should return from main normally whenever possible instead of using exit(). The value returned by your program can be used when it was launched by another program. A return value of 0 means no error, and a non-zero value means anything you want, and you can use that return value in the main program to do stuff differently. Needless to say, it's not often used.
14th Sep 2016, 6:15 PM
Zen
Zen - avatar
+ 3
exit 0 is successfully exiting the program as intended exit 1 is exit failure or can be a program crashed. I believe in c++ this is return 0; and exit 0 is written in c. but it can be used with c++ if it's what you desire.
14th Sep 2016, 6:16 PM
Name Less
Name Less - avatar
0
Thank you so much. @Zen @Name less
14th Sep 2016, 6:21 PM
naveen raj
naveen raj - avatar