[cs631apue] exit() vs return in c programs

Jan Schaumann jschauma at stevens.edu
Wed Sep 10 17:03:44 EDT 2014


Sadia Akhter <sakhter at stevens.edu> wrote:
 
> 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?

In short: the 'main' function is defined as returning an int; the
process effectively runs exit(main(...)).  Calling exit(3) from within
main() is functionally identical.

We will discuss this in some detail in Lecture 5.  If you like to read
ahead, you can find the answers in Chapter 7 of Stevens.

-Jan


More information about the cs631apue mailing list