The main function is a good example of how a C + + program can pass an array to a function.
Sometimes we need to pass arguments to main, which defines the main function
int Main (intChar *argv[]); // argv represents an array whose elements are pointers to C-style strings // ARGC represents the number of strings in a function // argv The first element points to the name of the program or an empty string, the next element is to pass the arguments provided by the command line, and the element value after the last pointer is guaranteed to be 0
ARGV represents an array whose elements are pointers to C-style strings argc represent the number of strings in a function argv the first element points to the name of the program or an empty string, the next element is to pass the arguments provided by the command line, and the element value after the last pointer is guaranteed to be 0
Examples are as follows:
int Main (intChar *argv[]) { "" << argc < < Endl; for (int0; i < argc; i++) { "" << argv[i] << endl; } return 0 ;}
The output is as follows:
1 Argv:e:\project\test\codetest\debug\codetest.exe
Because no arguments are entered under the console, the ARGC contains only 1 strings, which is the path of the EXE
Under the console, first enter the path of the EXE and enter the actual parameters, the results are as follows
[C + +] Main: Handling Command-line options