#include<stdio.h>
main()
{
char *name[]={"zhang","gou","xu","zheng","mao","zhao","li","bai","qing"};
printf("%s\n",*name[1]);
}
此時程序無運行結果。而去掉name前的*之後運行結果正確,為“gou”,請問該如何理解字符型指針數組,name[1]難道不是一個指針嗎?它的值不是應該為地址嗎?該如何理解呢?
#include<stdio.h>
main()
{
char *name[]={"zhang","gou","xu","zheng","mao","zhao","li","bai","qing"};
printf("%s\n",name[1]);
}
char *name[]; //定義了指針數組,每一個元素是一個字符指針變量,被分別初始化為各個字符串的起始地址。
printf中%s需要一個字符串的地址,所以name[1]就是,是“gou”的起始地址。