If you have an array then used in expressions it is implicitly converted (with rare exceptions) to a pointer to its first element.
On the other hand, a function parameter having an array type is adjusted by the compiler to pointer to the array element type.
For example if you declared a function like
char* fcn( char *para[] );
then the compiler will adjust the function declaration the following way
char* fcn( char **para );
You even may include the both declarations in your program though the compiler can issue a message that there are redundant declarations.
So if you have a function like this
char* fcn( char *para[] );
and in the caller you have an array like this
char *arg[] = {"XX", "YY", "ZZ"};
then the function parameter and the array declared in the caller have array types with the same element type. So you may call the function like
fcn( arg );
The array used as the argument is implicitly converted to a pointer to its first element.
The type of array elements is char *
. So a pointer to an element of the array will have the type char **
.
That is this function call
fcn( arg );
is equivalent to
fcn( &arg[0] );
Dereferencing the pointer you will get the first element of the array having the type char *
.
If you will write the expression
&arg
then the type of the expression will be char * ( * )[3]
. Dereferencing the pointer you will get the original array of the type char *[3]
.
Here is a demonstrative program
#include <stdio.h>
void f( char **arg )
{
printf( "sizeof( *arg ) = %zu\n", sizeof( *arg ) );
}
void g( char * ( *arg )[3] )
{
printf( "sizeof( *arg ) = %zu\n", sizeof( *arg ) );
}
int main(void)
{
char * arg[] = { "XX", "YY", "ZZ" };
f( arg );
g( &arg );
return 0;
}
The program output is
sizeof( *arg ) = 8
sizeof( *arg ) = 24