想問一下以下程序中printf輸出的都是什麼數字,與數組中的數字和位置有什麼關系
#include
int main(int argc, const char * argv[]) {
int a[5] = {3,4,8,9,10};
double *p = (double *)&a;
printf("%d\n",(double *)p);
int *q = p;
printf("%d\n",*q);
//
int b[7] = {3,4,8,9,10,11,12};
double *x = (double *)&b;
printf("%d\n", *x);
int *y = x;
printf("%d\n",*y);
//
int d[6] = {3,4,8,9,10,11};
double *j = (double *)&d;
printf("%d\n",*j);
int *k = j;
printf("%d\n",*k);
//
int c[5] = {3,4,8,9,10};
double *n = (double *)&c;
printf("%d\n",*n);
int *m = n;
printf("%d\n",*m);
return 0;
}
比如 double *p = (double *)&a; p指向了一個int數組,那麼編譯器知道p的類型是int型,那麼p+1就會移動sizeof(int)長度,指向了下一個元素