Among these declarations
char **argv = {"foo","boo"};
char *argv[] = {"foo","boo"};
char ****argv[] = {"foo","boo"};
only the second declaration is valid.
The first declaration is not valid because you may not use a list in braces with more than one expression to initialize a scalar object. And even if you will use only one string literal in braces in the first declaration nevertheless the type of the declared variable ( char ** ) and the type of the initializer ( char * ) are different and there is no implicit conversion between the types.
The third declaration is invalid because there is no implicit conversion between the type char * (the type of the string literals used as initializers) and the type char ****.
Valid declarations in C of character arrays using the presented list of initializers can be
char *argv1[] = {"foo","boo"};
char argv2[][3] = {"foo","boo"};
char argv3[][4] = {"foo","boo"};
Here is a demonstrative program
#include <stdio.h>
int main(void)
{
char *argv1[] = {"foo","boo"};
char argv2[][3] = {"foo","boo"};
char argv3[][4] = {"foo","boo"};
printf( "%s, %s\n", argv1[0], argv1[1] );
printf( "%3.3s, %3.3s\n", argv2[0], argv1[1] );
printf( "%s, %s\n", argv3[0], argv3[1] );
return 0;
}
Its output is
foo, boo
foo, boo
foo, boo
To make the first initialization correct you can write
char * p[] = {"foo","boo"}
char **argv = p;
Another way is to use the compound literal like
char **argv= ( char *[] ){"foo","boo"};
Here is one more demonstrative program
#include <stdio.h>
int main(void)
{
char **argv= ( char *[] ){"foo","boo"};
printf( "%s, %s\n", argv[0], argv[1] );
return 0;
}
Its output is
foo, boo
argvto a function likeexecv(), it needs a null pointer at the end, so it should be{"foo", "boo", NULL}-Wallbecause these examples makeclangrefuse to compile due to wildly mismatched types.char **argv = {"foo","boo"};initializes from incompatible pointer types.char ****argv[] = {"foo","boo"};has 3-Levels of indirection too many.char *argv[] = {"foo","boo"};is the only correct guess... Always compile with-Wall -Wextra -pedanticas part of your compile string.