9. 6. 3 pointer arrays as line function parameters
The indicator array has an important application, which can function as a function parameter。
As stated earlier, the c language program starts with the main function (the system calls the main function). Of course, this is viewed from the perspective of an ordinary programmer, and in fact the system did a lot of work before the mayn function, but these need not be considered。
This is how the main function is written in the current procedure:
As you can see, the parenthesis behind main is empty and has no content. This main function can actually have parameters, that is, when the system calls the main function, you can pass parameters to the main function。
Modify the main function so that it can receive the parameters that are passed in by the system. Amend the line of the definition of main to read as follows:
Note that the main function adds two squares, so that the main function can receive two incoming data: 1 the first is integer data; the second is a pointer array, which refers to the needle array as a function parameter. Although there is no specific reference to indicator arrays as functional symmetry, seeing them here amounts to knowing them。
Set a breakpoint to see what parameter content is passed to the main function when the system calls the main function by default, as shown in figure 9. 29。

Figure 9. 29 plains two shapes passed in
In figure 9. 29, it can be assumed that argv is a pointer array, the length of which is now 1, so it can be seen that the content of this element is the complete path file name of the enforceable document。
Argc is a number, which is currently 1 and it seems as if it is the length of the argv pointer array, which is the number of elements of the argv pointer array。
Consider the question: while the main function is called by the system and the system can pass the shape to the main function, can the system hand over additional parameters to the main function? Actually, it is. There are two ways. First of all。
The first approach is one that can be applied in the context of visual studio:
By right-clicking on the myproject project name in the solutions resource manager on the left side of visual studio, selecting the properties command in the pop-out shortcut menu, this will pop up a dialogue box, click on the debug option under configure properties on the left side of the dialogue box, and enter parameters on the right side in the command parameter, depending on the argv shown above as a character pointer array, it can be assumed that the parameters entered are many strings, separated by spaces between each string, for example by entering a1b2c3 and clicking on the ok button, as shown in figure 9. 30。
A code is then written so that the a1, b2, c3 entered in figure 9. 30 in the command parameters can be retrieved and exported so that the parameters that can be received in the program to the main function can be seen。
For example, the linux operating system has a column file command as follows:
The “-la” in this order is a parameter, which does not differ in any way from the a1, b2, c3 explained here. Now remove some of the unneeded codes and write some new codes as follows:


Figure 9. 30 project properties dialogue box

Implement this code and look at the results of the output, as shown in figure 9. 31。

Figure 9. 31 content of parameters received in the outputmain function
From this finding, it is assumed that three parameters, a1, b2, c3, have just been entered in figure 9. 30, which is received here, argc=4, indicating that four parameters were actually received, the first of which was seen as argv, which is actually the full path file name of the enforceable file, and it is concluded that the first element of the argv parameter (the pointer array) that the system passed to the main function was definitely the full path file name of the executable, after which the system passed the entered parameters a1, b2, c3 to the main function。
The code above, the fore cycle can be modified. The revised text would read as follows:

This example shows the advantage of the pointer array as a function parameter, since the number of parameters is uncertain when passing to the main function, and the length of each parameter is uncertain, so the pointer array can better meet this flexibility requirement。
As has just been said, there are two ways to artificially pass additional parameters to the main function through the system, and the second way to describe it is to enter the executing file name directly in the command line and follow the parameters behind。
Under catalogue c: \users\kuangxiang\desktop\c+\mysolution\debug, an enforceable file myproject. Exe, which has just been compiled as an enforceable document (. Exe file), can open a dos black window with cmd command, jump to the directory where the exe file is located with cd command in the black window, execute this enforceable document directly by command line and pass parameters to this enforceable document, as shown in figure 9. 32。

Figure 9. 32 time parameters when executing exe files and transmitting them to command lines
As you can see, as a result, the program received the parameters provided by the command line and exported the contents of the parameters received。




