+ 3

Why can't I return a void value in c++? Is it compulsory to return int value everytime?

13th Oct 2017, 3:20 PM
Manikanta
Manikanta - avatar
5 Respuestas
+ 10
only main is required to return an int
13th Oct 2017, 3:46 PM
jay
jay - avatar
+ 10
Utkarsh. Yes, you are correct. But void main is not standard c++. As programmers we should try to maintain the standard to ensure our code compiles and functions as expected in as many compilers as possible. Here is what the creator of the language says about void main. http://www.stroustrup.com/bs_faq2.html#void-main
18th Oct 2017, 11:36 AM
jay
jay - avatar
+ 4
this function returns nothing or has void as return void myfunction() { }
13th Oct 2017, 3:27 PM
Chrizzhigh
Chrizzhigh - avatar
+ 2
void main doesn't require an int value to be returned but if you use int main() then you will have to return value 0 at the end instead of getch.
18th Oct 2017, 11:16 AM
Utkarsh dasila
Utkarsh dasila - avatar
+ 2
Jay Thanks for the clarification.
18th Oct 2017, 11:59 AM
Utkarsh dasila
Utkarsh dasila - avatar