As we know, array name can't be assigned, sentence like:
char * array[], * point;
array = point; /* wrong */
array++; /* wrong */
But in main(int argc, char * argv[])
, argv++
is ok and works well.
What do i missing?
The second argument to main, usually called argv, is an array of strings. A string is just an array of characters, so argv is an array of arrays.
The second parameter, argv (argument vector), is an array of pointers to arrays of character objects. The array objects are null-terminated strings, representing the arguments that were entered on the command line when the program was started.
We use the array name as a pointer to store elements into the array. After that, we print the elements of the array using the same pointer. The compiler creates a pointer by default while we create an array. We do not need to handle subscripts separately if we learn how to use these pointers efficiently.
The argv parameter is an array of pointers to string that contains the parameters entered when the program was invoked at the UNIX command line. The argc integer contains a count of the number of parameters. This particular piece of code types out the command line parameters.
In your examples array
is a true array, and thus a non-modifiable l-value. In main, since it's declared in the parameter list, argv
is actually a char **
, i.e. a pointer which is modifiable.
It all boils down to the fact that char *array[]
means different things, depending on the context.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With