Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C

program entry point — concept C23

In a hosted environment execution begins at `int main(void)` or the `argc`/`argv` form; `argc` is nonnegative and `argv[argc]` is a null pointer. Returning from the initial `main` is equivalent to `exit`, and the status is delivered to the environment.

Version: C23

Syntax

program entry point

In a hosted environment execution begins at int main(void) or the argc/argv form; argc is nonnegative and argv[argc] is a null pointer. Returning from the initial main is equivalent to exit, and the status is delivered to the environment.

In main(int argc, char *argv[]), first check the argument count, then parse every value with complete validation and return EXIT_FAILURE on error. argv[0] may be an empty string, and the meaning of statuses other than 0, EXIT_SUCCESS, and EXIT_FAILURE depends on the environment.

Do not read argv[1] when argc <= 1, and do not assume argument encoding or console availability. A freestanding implementation may use another startup convention; these signatures describe a hosted environment, where reaching the end of the initial main returns zero.

Examples

#include <stdio.h>

int main(int argc, char *argv[]) { (void)argv; printf("%d\n", argc >= 1); return 0; }

Result

1

In a hosted environment execution begins at `int main(void)` or the `argc`/`argv` form; `argc` is nonnegative and `argv[argc]` is a null pointer. Returning from the initial `main` is equivalent to `exit`, and the status is delivered to the environment.

Sources