C/C++ Programmer's Guide (G06.27+, H06.03+)

Table Of Contents
Running and Debugging C and C++ Programs
HP C/C++ Programmer’s Guide for NonStop Systems429301-010
19-5
Parameters to the Function main
Parameters to the Function main
C enables you to declare up to three parameters to your program’s main function.
argc
is an integer value specifying the number of elements in the argument array argv.
argv
is the argument array. Each element (except for the last) points to a null-terminated
string. argv[0] points to the fully qualified name of the executing program. Each of
the elements argv[1] through argv[argc-1] points to one command-line
argument; argv[argc] has the pointer value NULL.
env
is the environment array. Each element (except for the last) points to a null-
terminated string containing the name and value of one environment parameter.
The last element has the pointer value NULL.
When declaring parameters to the function main(), note:
The parameters to main() are optional; you can declare no parameters, just argc
and argv, or all three parameters. You cannot declare env alone.
The identifiers argc, argv, and env are simply the traditional names of three
parameters to main(); you can use identifiers of your own choosing.
The elements of the environment array env point to strings of the form:
"param-name=param-value"
where param-name is the name of the environment parameter and param-value
is its value.
The putenv() function sets the value of a parameter in the environment array,
and the getenv() function retrieves the value of a parameter in the environment
array.
Use env and putenv() with caution, however. The environment parameter of
main() is not updated when the environment array is enlarged or moved. Therefore,
using the env parameter after invoking putenv() might result in inaccurate results. If
you need to modify and examine the environment array, you should use the extermal
variable environ, which always has the correct value.
int main(int argc, char *argv[], char *env[]);