Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why the array name argv can be assigned?

Tags:

c

argv

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?

like image 944
Liao Pengyu Avatar asked Nov 21 '12 19:11

Liao Pengyu


People also ask

Is argv an array of arrays?

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.

What is argv array?

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.

Why an array name is also called a pointer?

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.

What is in argv array in C?

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.


1 Answers

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.

like image 55
cnicutar Avatar answered Sep 25 '22 05:09

cnicutar