- 1
Why can't the main function in C++ be of type void?
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++
- 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.