+ 2
can a code have multiple main functions? if no why?
4 Answers
+ 9
It's the same thing as having two similar, non-overloaded functions in your program. Consider:
#include <iostream>
void cookie() { std::cout << "Hello"; }
void cookie() { std::cout << "World"; }
int main()
{
cookie();
return 0;
}
// The compiler complains
// Your main wouldn't know which one to invoke.
Similarly, if your program had two main functions, your operating system which calls main() wouldn't know which one to invoke, in normal circumstances.
+ 1
đ
đ
0
no