2

Possible Duplicate:
What should main() return in C/C++?
why do we give int main in c++ and not void main?

I've started learning C++ and the following question came up to my mind: main() always return int? Cannot I declare void main() instead of int main()?

Thanks you!

Community
  • 1
  • 1
Bouchard
  • 77
  • 1
  • 10

2 Answers2

6

Yes, main() must return int. The return value is passed back to the operating system, to indicate whether the program ran successfully: zero means success.

However, you can leave the return statement out of main (and only main) if you like; in that case, it will return zero.

Mike Seymour
  • 249,747
  • 28
  • 448
  • 644
1

It has to return an integer value. The returned value tells the computer what, if any, error codes there were. Returning 0 will tell it that there were no errors in the program.

Corey Adler
  • 15,897
  • 18
  • 66
  • 80