+ 6

why sometimes, void is used as data type of a 'main ()' function ??

14th Mar 2017, 4:48 AM
Harsh Bhardwaj
Harsh Bhardwaj - avatar
7 Answers
+ 23
every function return some value but sometimes there is no need of returning some value then void is used for void returns
14th Mar 2017, 4:52 AM
Mansi Dagla
Mansi Dagla - avatar
+ 3
no, not now. In c++11 main can only and must return integer. What you use is not standard of c++ in its new compiler.
14th Mar 2017, 4:51 AM
Aditya kumar pandey
Aditya kumar pandey - avatar
+ 3
@aditya K.P. it means void is never used in c++.
14th Mar 2017, 5:00 AM
Harsh Bhardwaj
Harsh Bhardwaj - avatar
+ 3
A function may return or may not return a value, if a function does then the specified return type is mention in the function declaration/definition else VOID is used if the function is not returning a value.
15th Mar 2017, 12:58 PM
MD SHEIKH AZARUDDIN
MD SHEIKH AZARUDDIN - avatar
+ 2
no, I am just saying that you can not use void or any other type unless integer for and only for main function. And you can use any type for other. In 2006, bell lab and c++ community take some decision for c++ future. It only for main() function
14th Mar 2017, 5:03 AM
Aditya kumar pandey
Aditya kumar pandey - avatar
+ 2
The return type of main is a integer, as it is the execution status. If the main function returns 0 - all fine, something else is an error. Some compilers just can fix it by changing it while compiling, some just ignore it, like the one by Microsoft, as Windows ignores the return status as well. Integer is the correct way.
14th Mar 2017, 5:46 AM
spotbot2k
spotbot2k - avatar
+ 1
because u will be using cout keywords in those functions and hence no return keywords.
16th Mar 2017, 4:52 PM
Gaurav Sharma
Gaurav Sharma - avatar