can any one help me?

is main() function a pre defined function or a user defined function?

thank you

10 Years
Discussion Span
Last Post by vijayan121

Both? It's predefined in that you have to define it the way that C++ expects, but it's user defined in that you still have to define it. Does that make sense?


main is a function written by the user, but it is special in several ways. as per ISO/IEC 14882(E):
3.6.1-1a program shall contain a global function called main, which is the designated start of the program. ...
3.6.1-2 an implementation shall not predefine the main function. this function shall not be overloaded. it shall have a return type of type int, but otherwise its type is implementation-defined. all implementations shall allow both of the following definitions of main: int main() { /* ... */ } and int main(int argc, char* argv[]) { /* ... */ }
3.6.1-3 the function main shall not be used (called) within a program. The linkage of main is implementation-defined

so it is a function defined by the user; but unlike other user defined functions, it must be in the global namespace, it can not return anything other than an int, it cannot be overloaded, it cannot be called (implementation defined linkage, usually different from the linkage for other functions) and it need not contain a return statement (assumed return 0).

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.