views:

82

answers:

2

Possible Duplicate:
What should main() return in C/C++?

This is a pretty basic question, I guess.

I've been programming for a year now but a friend of mine surprised me with a rather stupefying question.

Programs that start with 'int main()' on C++ seem to compile perfectly even with 'return 0;' removed and not replaced by any other return statement. And without a return statement at all, the program still shows that 'Process returned 0'.

Does this have any explanation? Sorry if my question is silly!

+1  A: 

From the accepted answer of What should main() return in C/C++?

It's also worth noting that in C++, int main() can be left without a return value at which point it defaults to returning 0. This is also true with a C99 program. Whether return 0 should be omitted or not is open to debate.

polygenelubricants
+5  A: 

§3.6.1/5:

A return statement in main has the effect of leaving the main function (destroying any objects with automatic storage duration) and calling exit with the return value as the argument. If control reaches the end of main without encountering a return statement, the effect is that of executing return 0;

GMan