Two formal parameters are required in the main
function in order to enable the program to address data that has been entered in the parameter line (see "Input of parameters for the main function"):
int main(int argc, char *argv[])
The names of the parameters (argc, argv) may be freely selected, but these are the names commonly used in the UNIX operating system.
The first parameter argc indicates the number of parameters that have been passed (including the program name).
The second parameter argv is a pointer to an array of char pointers (strings). The program name (in argv[0]) and all entered parameters are stored in it as strings that are terminated with the null byte (\0).
Example
The following example outputs the program name and all entered parameters.
#include <stdio.h> int main(int argc, char *argv[]) { int i; printf("Program name: %s\n", argv[0]); for (i=1; i<argc; ++i) printf("%d. parameter is: %s\n", i, argv[i]); return 0; }