enter 發表於 2014-6-25 15:25:57

C語言中指標使用時機的問題?

這是書上的範例,用一個字串二維陣列,然後輸入前面的顏色單字,出現後面的顏色意義。程式碼如下:

#include <stdio.h>
#include <string.h>

char *p[]={
"red","hot",
"green","peace",
"blue","suck",
"yellow","bright",
"white","pure",
"",""};

int main(void){
int x;
char color;
printf("enter a color:\n");
gets(color);
for(x=0;*p;x++)
{if (!strcmp(p,color))
printf("%s is %s.",color,p);
}
return 0;
}

搞不懂的就是為何前面藍字部份是可以用指標*p[][],而紅字部份則沒有指標*的符號?
我有試著把它們加上指標符號,結果是錯的。那請問一下,後面為何不用指標符號?

thanks
頁: [1]
查看完整版本: C語言中指標使用時機的問題?