Why does main have void return type, even though there are executable statements within? Is it due to the lack of the 'return'? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why does main have void return type, even though there are executable statements within? Is it due to the lack of the 'return'?

20th Jan 2021, 4:16 PM
Hillary Moneke
Hillary Moneke - avatar
2 Answers
+ 4
Which language are you talking about here ?
20th Jan 2021, 4:20 PM
Arsenic
Arsenic - avatar
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.
20th Jan 2021, 5:20 PM
CHANDAN ROY
CHANDAN ROY - avatar