Does int main() need a declaration on C++?

main() is a special function in C++.

Some important things to remember about main() are:

  1. The linker requires that one and only one main() function exist when creating an executable program.
  2. The compiler expects a main() function in one of the following two forms:

    int main () { body } 
    int main (int argc, char *argv[]) { body } 

    where body is zero or more statements

    An additional acceptable form is implementation specific and provides a list of the environment variables at the time the function is called:

    int main (int argc, char* argv[], char *envp[]) { body }

    The coder must provide the 'definition' of main using one of these acceptable forms, but the coder does not need to provide a declaration. The coded definiton is accepted by the compiler as the declaration of main().

  3. If no return statement is provided, the compiler will provide a return 0; as the last statement in the function body.