Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
sir i want to know about main(), it is a user defined or library function?
Posted

The question is malposed: "user defined" and "library" are not necessarily mutually exclusive, since all function contained in a library (in term of the compiler point of view) are "user defined".

main() is actually called by a function that sits in the default library that is "jumped into" by the OS at program startup.

main() itself is not inside the default library, hence the "user" (in the sense of the "compiler user") must provide it somehow.

He can do that either by writing it in one his own sources, or by linking its project to a some framework library that contains it.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 10-Aug-11 1:02am    
Best answer so far. My 5.
--SA
 
Share this answer
 
Comments
Albert Holguin 9-Aug-11 10:51am    
that covers it nicely (for standard development), my 5
If you create your project using the Visual Studio Wizard it will make a main for you (even if you don't want it to).
 
Share this answer
 
"A program must contain a function called main(). This function is the designated start of the program. The function is not predefined by the compiler, it cannot be overloaded, and its type is implementation dependent." The Annotated C++ Reference Manual, M. A. Ellis & B. Stroustrup, Addison-Wesley, 1986, Section 3.4.

Indeed, it is a user-defined function. You will find it somewhere in the source code, in a .cpp file.

Also read Where the main() function exists in c++ ? Is it a user defined function?[^]
 
Share this answer
 
v2
Comments
Emilio Garavaglia 9-Aug-11 6:09am    
My vote of 1:
The answer citation is corret, but the conclusion is misconceived.
main() can stay in a library as wel, not necessarily between the user sources of an app.

Just find main() in an MFC app, for example!
Albert Holguin 9-Aug-11 10:50am    
You're right... but don't think the answer deserved a 1 for that.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900