假设我有一个指针数组:
char *names[] = { "Za" , "John"};
我可以这样声明吗:(?)
char **names = { "Za" , "John" }
我尝试这样做的原因是,我正在尝试增加数组以打印其内容,这样我就可以:
printf("%s \n" , *(++names))
所以我可以让printf打印“John”。
我尝试了声明char**names,编译时收到以下警告:
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
谢谢。
最佳答案
只要做char **pCurrentName = names;
,你就可以做printf("%s \n" , *(++pCurrentName))
。
关于c - 指针数组的不同声明,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22430648/