Why can not we have 2 main functions in a single program | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 3

Why can not we have 2 main functions in a single program

26th Aug 2018, 7:16 AM
Sushil Shinde
Sushil Shinde - avatar
9 ответов
+ 7
No we can have one and only one main() in every executable. When you run the executable, os runs the main function in that executable. It will create ambiguity if there are two main functions.
26th Aug 2018, 7:22 AM
code learner
code learner - avatar
+ 3
A previous discussion regarding main function, you might find to be interesting: https://www.sololearn.com/Discuss/1349922/?ref=app
26th Aug 2018, 7:52 AM
Ipang
+ 3
Sounds like “Why can’t we have 2 mothers?” Because to “born” a program we need only 1 Main() method and one pair of straight hands☺️
26th Aug 2018, 8:18 AM
Bohdan Barylo
Bohdan Barylo - avatar
+ 2
if we have tow main function the compiler confused and says from where i can excute the program? from main1 or 2
27th Aug 2018, 8:15 AM
olbab omer
olbab omer - avatar
+ 2
it will create an ambiguity for the compiler where to start the program
29th Aug 2018, 6:02 AM
Michael Mamo
Michael Mamo - avatar
+ 2
that's like having two start buttons. which start button do you press?
29th Aug 2018, 10:49 PM
Vincent Kwok
Vincent Kwok - avatar
+ 2
any program will start execution from main func so if there is two main func then the compiler will get confused where to start the prog running
9th Oct 2018, 7:02 AM
Michael Mamo
Michael Mamo - avatar
+ 1
main is the entry point to your app so there's one main to run the app thread
11th Sep 2018, 1:16 AM
M Alameen
0
because main is the entry point to your app so there must be one entry to app . suppose you have 2 main which one to be thread to app and compiler doesnot know which one to start with
15th Oct 2018, 1:00 PM
M Alameen