0
int main()
{
    return 1;
}

int main()
{
    return 14;
}

int main()
{

}

Above codes compiled successfully on Microsoft Visual Studio 2013 and no problems occurred.

So what kind of problems the above codes may cause?

Gaith
  • 798
  • 8
  • 19
  • 3
    Problems for anything that checks if your program finished successfully and gets a false negative. – chris Dec 29 '13 at 11:04
  • 2
    @nrathaus Unfortunately, no. `main()` is implicitly assumed to return 0 if nothing is returned. (This is horrible behavior, though.) –  Dec 29 '13 at 11:06
  • Ok, still a bad thing to do @H2C03 – Noam Rathaus Dec 29 '13 at 11:07
  • @nrathaus I didn't say it's not a bad thing to do (conversely, I said that it **is**). But your comment is still incorrect (and even worse, it's misleading because it's got an upvote), please remove it. –  Dec 29 '13 at 11:08
  • @nrathaus: No it's not. There is absolutely nothing wrong with omitting `return 0` in `main`. – Lightness Races in Orbit Feb 12 '14 at 18:19

1 Answers1

3

The return value from your main method is passed to whatever caused your program to be run.

In many cases (manual running) this return value is ignored, but in other places it can be used to change logic for example in batch or shell script programs.

The general convention is that a return code of 0 is success, anything else is a specific error or signal that can then be acted on by the calling program/script/user/whatever.

Tim B
  • 40,716
  • 16
  • 83
  • 128