假设我有一个指针数组:
char *names[] = { "Za" , "John"};
我可以这样声明:(?)
char **names = { "Za" , "John" }
我试图这样做的原因是我试图增加数组以打印其内容,以便我可以这样做:
printf("%s \n" , *(++names))
所以我可以让printf打印“John”。
我尝试了声明char **名称,并在编译时收到以下警告:
test.c: In function ‘main’:
test.c:6:2: warning: initialization from incompatible pointer type [enabled by default]
char **names = { "Za" , "John"};
^
test.c:6:2: warning: (near initialization for ‘names’) [enabled by default]
test.c:6:2: warning: excess elements in scalar initializer [enabled by default]
test.c:6:2: warning: (near initialization for ‘names’) [enabled by default]
P.S我的C文件名是test.c
感谢。
答案 0 :(得分:2)
只需char **pCurrentName = names;
,然后就可以printf("%s \n" , *(++pCurrentName))
。