+ 3

Is main() a user-defined function or a predefined function ?

We do write content in main() but we can't name the main function anything, we have to name it main(). Then what is main() user-defined or predefined?

14th Sep 2019, 9:24 AM
Sayan Mukherjee
Sayan Mukherjee - avatar
9 Answers
+ 5
The jvm searches for a method called main as a starting point to begin executing your code, it only knows that there should be a main method somewere in one of your classes so yes you need to define it as it's not built in.
14th Sep 2019, 9:39 AM
D_Stark
D_Stark - avatar
+ 5
~ swim ~ D_Stark What about in C and C++? Is main() predefined or user defined? I read that main() cannot be overloaded and is pre-defined in the compiler but the its implementation is done by the programmer/user. So it's both predefined and user-defined. What are your reviews about it?
14th Sep 2019, 1:16 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 3
I see, now it makes sense to me. Thanks for clarification.
14th Sep 2019, 3:47 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 3
It can be considered as a starting point for the program because the control flow in C starts with main() rather like languages as python will execute the code line by line. Main() cannot be considered as a predefined function because the user himself should write it's definition. And it is not completely user defined because the compiler pre-declared it. In c main is not a keyword as it can be used as a variable name also.
15th Sep 2019, 4:46 AM
Manoj
Manoj - avatar
+ 2
So is it predefined or user-defined or both?
14th Sep 2019, 3:13 PM
blACk sh4d0w
blACk sh4d0w - avatar