cpp/language/main function

A program shall contain a global function named, which is the designated start of the program in hosted environment. It shall have one of the following forms:

The names of and  are arbitrary, as well as the representation of the types of the parameters:  is equally valid.

A very common implementation-defined form of has a third argument (in addition to  and ), of type, pointing at an array of pointers to the execution environment variables.

Explanation
The function is called at program startup after  of the non-local objects with static. It is the designated entry point to a program that is executed in hosted environment (that is, with an operating system). The entry points to freestanding programs (boot loaders, OS kernels, etc) are implementation-defined.

The parameters of the two-parameter form of the main function allow arbitrary multibyte character strings to be passed from the execution environment (these are typically known as command line arguments), the pointers .. point at the first characters in each of these strings. (if non-null) is the pointer to the initial character of a null-terminated multibyte string that represents the name used to invoke the program itself (or an empty string if this is not supported by the execution environment). The strings are modifiable, although these modifications do not propagate back to the execution environment: they can be used, for example, with std. The size of the array pointed to by is at least, and the last element, , is guaranteed to be a null pointer.

The function has several special properties: @1@ It cannot be used anywhere in the program
 * @a@ in particular, it cannot be called recursively
 * @b@ its address cannot be taken

@2@ It cannot be predefined and cannot be overloaded: effectively, the name in the global namespace is reserved for functions (although it can be used to name classes, namespaces, enumerations, and any entity in a non-global namespace, except that an entity named  cannot be declared with C  in any namespace. @3@ It cannot be  declared with any language linkage,, or . @4@ The body of the main function does not need to contain the : if control reaches the end of  without encountering a return statement, the effect is that of executing . @5@ Execution of the return (or the implicit return upon reaching the end of main) is equivalent to first leaving the function normally (which destroys the objects with automatic storage duration) and then calling std with the same argument as the argument of the . (std then destroys static objects and terminates the program).