C++ void return type of main()

后端 未结 8 2428
灰色年华
灰色年华 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:21

    C++ does not allow main to have a void return type. The published C++ standard requires it to be int. Some C++ compilers allow you to use void, but that's not recommended. In general, the OS doesn't care one way or the other. A specific OS might require a program to give a return value, but it doesn't necessarily have to come from main's return value. If the C++ compiler allows void, then it probably provides some other means of specifying the program's exit code.

提交回复
热议问题