Edit

Share via


Arguments to main

ANSI 2.1.2.2.1 The semantics of the arguments to main

In Microsoft C, the function called at program startup is called main. There's no prototype declared for main, and it can be defined with zero, two, or three parameters:

int main( void )
int main( int argc, char *argv[] )
int main( int argc, char *argv[], char *envp[] )

The third line above, where main accepts three parameters, is a Microsoft extension to the ANSI C standard. The third parameter, envp, is an array of pointers to environment variables. The envp array is terminated by a null pointer. For more information about main and envp, see The main function and program execution.

The variable argc never holds a negative value.

The array of strings ends with argv[argc], which contains a null pointer.

All elements of the argv array are pointers to strings.

A program invoked with no command-line arguments will receive a value of 1 for argc, as the name of the executable file is placed in argv[0]. (In MS-DOS versions prior to 3.0, the executable-file name isn't available. The letter "C" is placed in argv[0].) Strings pointed to by argv[1] through argv[argc - 1] represent program parameters.

The parameters argc and argv are modifiable and retain their last-stored values between program startup and program termination.

See also

Environment