c sizeof

 
 
#include "iostream"
using namespace std;

int  main(int argc, char const *argv[]){
	int *a[2][3];
	printf("sizeof(*a[0][0]) is %lu\n", sizeof(*a[0][0]));
	printf("sizeof(a[0][0]) is %lu\n", sizeof(a[0][0]));
	printf("sizeof(*a[0]) is %lu\n", sizeof(*a[0]));
	printf("sizeof(a[0]) is %lu\n", sizeof(a[0]));
	printf("sizeof(*a) is %lu\n", sizeof(*a));
	printf("sizeof(a) is %lu\n", sizeof(a));
	return 0;
}

the result is :

sizeof(*a[0][0]) is 4
sizeof(a[0][0]) is 8
sizeof(*a[0]) is 8
sizeof(a[0]) is 24
sizeof(*a) is 24
sizeof(a) is 48
[Finished in 0.4s]

分析:a为一个二维的指针数组,其中的每一个元素为一个指针,指向一个int型的值。

a[0][0] a[0][1] a[0][2]
a[1][0] a[1][1] a[1][2]


a指向整个数组区域。(64bit系统中,指针占8bit)

*a同a[0],都指向数组a的第一行

*a[0]同a[0][0],都指向数组a的第一行的第一个元素

*a[0][0]为元素a[0][0]指向的int型的值


你可能感兴趣的:(c sizeof)