C++ void return type of main()

后端 未结 8 2445
灰色年华
灰色年华 2020-12-11 01:58

Some C++ compilers allow the main function to have return type void. But doesn\'t the Operating System require int type value returned to specify

8条回答
  •  心在旅途
    2020-12-11 02:22

    But doesn't OS require int type value returned to specify whether program 
    ended well or not?
    

    Why would it always? On windows when you double click on the icon, the process dies after it ends. OS do not check for the return type there. Even on linux if you just run the binary as ./runBinary, it simply runs and exits. The OS do not show message by itself that it fails or succeeds.

    All the above answers are right that the standard says it is int, but some compilers allow void too.

提交回复
热议问题