When a program terminates simply by executing the last statement in main, its exit status is undefined. If another program needs to use this exit status, you mustn’t let this happen. In such a case, make certain that you exit or return from main with a defined exit status.
Asked
Active
Viewed 42 times
-1
-
Does this answer your question? [What should main() return in C and C++?](https://stackoverflow.com/questions/204476/what-should-main-return-in-c-and-c) – zerocukor287 Dec 06 '21 at 07:59
-
That is incorrect. If `main` does not `return` a value, the compiler assumes it returns 0. It's true for all *other* functions. – Weather Vane Dec 06 '21 at 07:59
-
What C standard version is covered by that book? Implicit `return 0;` for `main` was already part of C99. If that book uses an even older version, you should get rid of it. There were lots of improvements in C99. – Gerhardh Dec 06 '21 at 08:35
1 Answers
3
What is says is that if you don't have a return
statement from the main
function, the returned value is indeterminate (just like missing a return
statement from another function declared to return a value).
However this is no longer true. Since the C99 standard if there's no explicit return
statement in the main
function, the compiler will add an implicit return 0;
at the end.

Some programmer dude
- 400,186
- 35
- 402
- 621