+ 2

can a code have multiple main functions? if no why?

22nd May 2017, 2:07 PM
LAKSHMI NARAYANA SANTHA
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.
23rd May 2017, 3:00 AM
Hatsy Rei
Hatsy Rei - avatar
+ 1
🙅🙅
22nd May 2017, 2:25 PM
Julian Aung
Julian Aung - avatar
0
no
22nd May 2017, 2:14 PM
Vishal Prajapati