#include<stdio.h>
main()
{
int a[]={10,20,30,40,50};
char *p;
int i;
p=(char*)a;
for(i=0;i<8;i++)
{
printf("%d %u\n",*p,p);
p++;
}
return 0;
}
请解释数组如何存储在内存中的行为?
答案 0 :(得分:2)
您的数组存储在一个连续的内存块中:
index: 0 | 1 | 2 | 3 | 4
bytes: 0 1 2 3 | 4 5 6 7 | 8 9 10 11 | 12 13 14 15 | 16 17 18 19
values: 10 | 20 | 30 | 40 | 50
这些问题对您有所帮助:
Address of first element in static declaration of array
How does this pointer arithmetic work?