- 1

Why can't the main function in C++ be of type void?

19th Jul 2016, 4:41 PM
chaitanya guruprasad
chaitanya guruprasad - avatar
2 Antworten
0
Not satisfied. When main() is a function, i should have full authority in deciding the return type like i do in c. Why only int type in c++
19th Jul 2016, 7:06 PM
chaitanya guruprasad
chaitanya guruprasad - avatar
- 1
Because void means the function cannot return anything. When a C++ program ends in main, return 0; is used to end the program safely, even if you didn't put it there, your compiler will just assume there is a return 0 at the end of your program. If your main is void, then the main cannot return 0, therefore the program cannot end safely. Thanks for your question.
19th Jul 2016, 6:40 PM
Cohen Creber
Cohen Creber - avatar