You must be asking about int main(int argc, char *argv[]). In fact, there is no problem at all if you want to write like this int main(int argc, char **argv).
If you define a char *s = '2333', what does this s refer to? The first address of the string. In the same way, what does *argv[1] store? The first address of the first string. You can simply understand it this way. If you want to go deeper, you can read the book.
char *s = "23333";
char *z = "34444";
char *argv[] = {s, z};
int a = 0;
int b = 1;
int c[] = {a, b};
It’s interesting~ In fact, sometimes if you want to understand, it’s just a matter of changing the way you write it.
char *argv[] is an array. The elements of the array are char *. Each char * is used to point to the first address of a string. So argv[1] points to the first address of the second string (we assume that the first string is argv[0]). Therefore, argv[1] is also an address, which is the first address of a string.
Arrays and pointers can only be considered the same when used as function parameters, so char *argv[] here can also be written as char **argv. I don’t know if this is easier to understand.
Here*argv[] defines a pointer array, with n array elements of pointer type (argv[0],argv[1],...,argv[n]) (argv[1 ] is the second element of the pointer array, which is still a pointer. *(argv+1) is the value pointed to by the second element of the pointer array, which is a value )
.
argv[1] is the address. How to call it needs to be analyzed based on the specific context code. Generally, argv[1] is placed in another pointer int *p = (int*)argv[1];, and then *p gets the value of *argv[1] below.
argv[1] is equivalent to *(argv+1)
You must be asking about
int main(int argc, char *argv[])
. In fact, there is no problem at all if you want to write like thisint main(int argc, char **argv)
.If you define a
char *s = '2333'
, what does thiss
refer to? The first address of the string. In the same way, what does*argv[1]
store? The first address of the first string. You can simply understand it this way. If you want to go deeper, you can read the book.It’s interesting~ In fact, sometimes if you want to understand, it’s just a matter of changing the way you write it.
The original poster wants to say
*argv[]
in
, right?char *argv[]
is an array. The elements of the array arechar *
. Eachchar *
is used to point to the first address of a string. So argv[1] points to the first address of the second string (we assume that the first string is argv[0]). Therefore,argv[1]
is also an address, which is the first address of a string.Arrays and pointers can only be considered the same when used as function parameters, so
char *argv[]
here can also be written aschar **argv
. I don’t know if this is easier to understand.The type when passing parameters is *argv[], which is equivalent to **argv, which is a pointer to a pointer
Here
.*argv[]
defines a pointer array, with n array elements of pointer type (argv[0],argv[1],...,argv[n]
)(
argv[1 ]
is the second element of the pointer array, which is still a pointer.*(argv+1)
is the value pointed to by the second element of the pointer array, which is a value )argv[1]
is the address. How to call it needs to be analyzed based on the specific context code.Generally,
argv[1]
is placed in another pointerint *p = (int*)argv[1];
, and then*p
gets the value of*argv[1]
below.The name of the array is actually an address, so there is nothing wrong with using it this way.
In C language, an array is originally an address