The function main can be declared with or without arguments that pass program parameters and environment settings to the program. Although any name can be given to these parameters, they are usually referred to as argc, argv, and envp.
argc | Is the argument count. It has type int and indicates how many arguments are entered on the command line. |
argv | Is the argument vector. It is an array of pointers to char array objects. These char objects are null-terminated strings that are the program arguments passed to the program when it is invoked. |
envp | Is an optional environment pointer. It is an array of pointers to char objects that are the environment variables available to the program. These have the form name=value. The system determines the value of this parameter during program initialization (before calling main). Because you can use the function getenv to get the value of these pointers, there is usually no need to declare this parameter. |
The value of argc indicates the number of pointers in the array argv. If a program name is available, the first element in argv points to a character array that contains the program name or the invocation name of the program that is being run. If the name cannot be determined, the first element in argv points to a null character.
This name is counted as one of the arguments to the function main. For example, if only the program name is entered on the command line, argc has a value of 1 and argv[0] points to the program name.
Regardless of the number of arguments entered on the command line, argv[argc] always contains NULL.
Functions
Function
Calls
Type
Specifiers
Examples of
Function Calls
Examples of
Function Declarations
Examples of
Function Definitions