标签:
利用&查看内存地址
1 #include <stdio.h>
2
3 int main(void)
4 {
5 int list[3]={1,1,1};
6 for (int i=0; i<3; i++)
7 {
8 printf("list[%d]‘s address: %p\n", i, &list[i]);
9 printf("Address of matrix: %p\n", &list); // &list changed to list would get the same
10 }
11 return 0;
12 }
结果:
list[0]‘s address: 0x7fff10fd4580
Address of matrix: 0x7fff10fd4580
list[1]‘s address: 0x7fff10fd4584
Address of matrix: 0x7fff10fd4580
list[2]‘s address: 0x7fff10fd4588
Address of matrix: 0x7fff10fd4580
可以看出,list的位置始终和它的第一个元素的地址一致。而由于元素数int, 所以占4个字节。
并且由于数组的元素在内存上是紧密排列的,所以地址都相差4.
标签:
原文地址:http://www.cnblogs.com/omnipotent/p/4181374.html