gpt4 book ai didi

c - 指针数组的不同声明

转载 作者:太空宇宙 更新时间:2023-11-04 08:43:54 25 4
gpt4 key购买 nike

假设我有一个指针数组:

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com