What is char * argv [] and how does it look like char ** argv

I can't figure out how char * argv [] is like char ** argv. Also, please let me know when to use pointers?

+4
source share
2 answers

A function parameter declared as having an array type silently adjusts to a pointer type. Thus, if you declare a function with a parameter of type int x[] , the parameter is of type int *x . Similarly, char *argv[] in the function parameter is the same as char **argv , since the array of pointers is set to a pointer to a pointer.

+8
source

Basically, char * argv[] is an array of char pointers, and char ** argv is a pointer to a char pointer.

As we pass it as a parameter to the char * argv[] function, we are set to a pointer type that points to the starting element of this array, char ** argv and are the same.

6.7.5.3 Declaration of functions (including prototypes) ...

7 Declaring a parameter as a '' type array must be adjusted to a "qualified type pointer", where type qualifiers (if any) are those that are specified in the [and] output of the array type. If the static keyword also appears inside [and] the output of the array type, then for each function call, the value of the corresponding actual argument should provide access to the first element of the array with at least as many elements as indicated by the size expression.

As you can see, we use both definitions of main , equivalent to -

 int main(int argc, char ** argv) 

and

 int main(int argc, char *argv[]) 
0
source

All Articles