New course! Every coder should learn Generative AI!
Try a free lesson0
Why does main have void return type, even though there are executable statements within? Is it due to the lack of the 'return'?
2 Answers
+ 4
Which language are you talking about here ?
0
Hillary Moneke
In all C/C++ programs (except where abnormal termination happens), the main() function doesn't return a value, or the user doesn't need to use a value returned by main(). Since void means the absence of value, it can be used as the return type of main() function to imply the absence of a return value.
This, however, is a non-standard and outdated practice. According to the standards, main() should return int, and the value should be 0 for normal termination and -1 for abnormal termination.