1
#include <stdio.h>
int main() {
int *a[2]; // an array of 2 int pointers
int (*b)[2];
// pointer to an array of 2 int (invalid until assigned) //
int c[2] = {1, 2}; // like b, but statically allocated
printf("size of int %ld\n", sizeof(int));
printf("size of array of 2 (int *) a=%ld\n", sizeof(a));
printf("size of ptr to an array of 2 (int) b=%ld\n", sizeof(b));
printf("size of array of 2 (int) c=%ld\n", sizeof(c));
return 0;
}
a
是2個整數指針的數組,所以不應該是2 * 4 = 8
?爲什麼sizeof(a)16? (sizeof int是4)
在GCC上測試。
如果您在64位機器上運行,您的指針大小可能爲8個字節,所以2個指針= 16個字節。什麼是你的機器上的sizeof(int *)? – zserge 2012-07-11 09:24:50