+ 3
Why can't I return a void value in c++? Is it compulsory to return int value everytime?
5 Respuestas
+ 10
only main is required to return an int
+ 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
+ 4
this function returns nothing or has void as return
void myfunction() {
}
+ 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.
+ 2
Jay
Thanks for the clarification.