Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ void return type of main()

Tags:

c++

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 whether the program ended well or not?

like image 249
B.Gen.Jack.O.Neill Avatar asked Sep 06 '10 14:09

B.Gen.Jack.O.Neill


1 Answers

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.

like image 66
Rob Kennedy Avatar answered Sep 21 '22 23:09

Rob Kennedy