Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C++

Program entry point: main

In a hosted environment, the global-scope main function is the entry point of a C++ program. It returns int, can receive startup arguments, and supplies the termination status.

Version: C++23; repository compiler flag, production runtime not attested

Syntax

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

In a hosted environment, a program contains exactly one global-scope main function. It is invoked in the main thread. In a freestanding environment, whether defining main is required is implementation-defined.

The two portable forms are int main() and int main(int argc, char* argv[]). void main() is not a standard form. argc is a non-negative argument count; argv[argc] is a null pointer. When argc > 0, argv[0] describes the program's invocation name or is an empty string; subsequent elements contain the remaining arguments.

return 0; indicates successful termination. Reaching the end of the body of main has the same effect. Returning destroys local objects with automatic storage duration, then calls std::exit with the result. You must not call main yourself or take its address.

The example prints nothing and returns 0. This entry targets C++23; the supplied source is an evolving draft, not a frozen C++23 publication. The repository compiler flag does not attest the production runtime.

Examples

int main()
{
    return 0;
}

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources