Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why return 0 from main() in a C program? [duplicate]

Tags:

c++

c

When writing a C/C++ program, specifically with latest compilers, why do we need to return an integer from the main() method? Like int main() and we return "return 0" from it. So what is the exact reason behind this?

like image 604
TheSpy Avatar asked Feb 01 '14 06:02

TheSpy


1 Answers

The return value of main() becomes the exit status of the process. Traditionally, an exit status of zero usually means “OK,” while any non-zero value indicates some kind of error. This is analogous with how many system calls likewise return zero or an error code.

Even more information at J. Leffler's epic answer to this, similar question: What should main() return in C and C++?

like image 87
BRPocock Avatar answered Oct 30 '22 17:10

BRPocock