[cs631apue] exit() vs return in c programs

Sadia Akhter sakhter at stevens.edu
Wed Sep 10 15:57:47 EDT 2014


I know it matters when exit() is called from any method other than main(). But I noticed that in the text book they always use exit() even in the main() function. That's why I was curious. I guess its more like common practice then. 

Thanks,
Sadia 

On Sep 10, 2014, at 3:50 PM, JIANLONG ZHOU <jzhou14 at stevens.edu> wrote:

> Hi, I think there is no difference when you use exit(0) or return 0 in main(), but different when you try to use in sub function. Simply return will exit from current function, but exit will terminate the program, here is the link you can look at: 
> http://stackoverflow.com/questions/17383015/difference-between-return-0-and-exit-0
> 
> Thanks,
> JIANLONG ZHOU
> On Sep 10, 2014, at 3:32 PM, Sadia Akhter <sakhter at stevens.edu> wrote:
> 
>> Hi,
>> 
>> In my previous experience with C, I have always used "return 0;" to return from main() function. Those were of course not any system programming codes. However, in the text book APUE, I noticed that they always use "exit(0)" in main(). Can anyone tell me why is that? Is there any significant difference between these two? Or is it just regular practice?
>> 
>> Thanks,
>> Sadia Akhter
>> _______________________________________________
>> cs631apue mailing list
>> cs631apue at lists.stevens.edu
>> https://lists.stevens.edu/mailman/listinfo/cs631apue
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.stevens.edu/pipermail/cs631apue/attachments/20140910/8995fa03/attachment.html>


More information about the cs631apue mailing list