+ 2

Why main function returns a integer ?

3rd Jan 2017, 10:42 PM
Victor Dantas
Victor Dantas - avatar
3 Answers
+ 6
It doenst metter actually, you can make it void and don't have to return anything
3rd Jan 2017, 10:43 PM
Nahuel
Nahuel - avatar
+ 4
because programs usually return with an integer code. 0 means regular exit, other means an error. depending the return value the caller can handle different outcomes.
3rd Jan 2017, 10:50 PM
DFX
DFX - avatar
+ 3
By cpp standard prohibited use of void on main function, this mean cpp main return a int. return 0 -> program normal end return negative value -> abnormal finish, like -1
4th Jan 2017, 2:38 AM
nextco
nextco - avatar