#includeint main() { int a[5] = {1,2,3,4,5}; /* 你能答對最後一條語句的輸出嗎?*/ int *ptr1 = (int *)(&a+1); int *ptr2 = (int *)((int)a+1); printf("&a = %d\n",(&a)); printf("(&a+1) = %d\n",(&a+1)); printf("a = %d\n",a); printf("(a+1) = %d\n",(a+1)); printf("(int)a+1 = %d\n",(int)a+1); printf("ptr1 = %d,*ptr2 = %d",ptr1[-1],*ptr2); // 輸出是多少? return 0; }
輸出:
printf("(&a+1) = %d\n",(&a+1));//加1是加了整個數組的大小
printf("(int)a+1 = %d\n",(int)a+1);//這裡加1是當成整數加1