本帖最後由 enter 於 2015-1-22 22:29 編輯
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char str[4][7]={"mary","desk","quit","gold"};
char *p;
int num[2][3][4]={
1,2,3,4, 5,6,7,8, 9,10,11,12,
13,14,15,16, 17,18,19,20, 21,22,23,24};
int *q;
p=str;
q=num; //這裡當成一維陣列的指標變數來想會比較清楚
printf("%c %c %c\n",str[1][3],*(*(str+1)+3),*(str[1]+3)); //k,k,k
printf("%s %s\n",str[2],str+2); //quit
printf("%s %s\n",str[2]+1,*(str+2)+1);//uit
printf("%s %s %s\n",(str[2]+2),*(str+3),str+3);//it,gold,gold
printf("%c %s\n",p[7],p+14);//要注意,用指標變數p來表示,則它的算法會將次陣列中未有元素的空格也一併計算進來
printf("%d %d %d %d\n",num[1][2][1],*(*(*(num+1)+2)+1),*(*(num[1]+2)+1),*(num[1][2]+1));//22
printf("%d",q[8]);//9
return 0;
} |