Arguments to main()
Go Up to The main() Function Index
Three parameters (arguments) are passed to
main by the C++Builder startup routine:
argc, an integer, is the number of command-line arguments passed to
main, including the name of the executable itself.
argvis an array of pointers to strings
argvis the full path name of the program being run.
argvpoints to the first string typed on the operating system command line after the program name.
argvpoints to the second string typed after the program name.
argv[argc-1]points to the last argument passed to
envis also an array of pointers to strings. Each element of
envholds a string of the form
ENVVARis the name of an environment variable, such as
valueis the value to which
ENVVARis set, such as
If you declare any of these parameters, you must declare them exactly in the order given:
env. For example, the following are all valid declarations of arguments to
int main() int main(int argc) /* legal but very unlikely */ int main(int argc, char *argv) int main(int argc, char *argv, char *env)]
The declaration int
main(int argc) is legal, but it is very unlikely that you would use
argc in your program without also using the elements of
env is also available through the global variable _environ.
For all platforms,
argv are also available via the global variables
Using main() with a Unicode application
The Unicode version of the
main function is:
int wmain (int argc, wchar_t *argv, wchar_t *env)
argv (and optional
envp) parameter(s) support(s) wide-characters.
_tmain function is a macro that expands to the appropriate version of the
main function depending upon the type of application:
int _tmain (int argc, _TCHAR *argv, _TCHAR *env)