第1个回答 2012-12-07
你的假设是不会成立的!因为定义的数组是整形,在32位计算机上,每个整形占4字节。数组是连续分配存储空间的。a[0]和 a[1]之差应该是4. 正确输出地址格式应该是以十六进制的!!!并且你的位数也不对
程序
#include <stdio.h>
int main()
{
int a[10]={11,12,13,14,15}, *p=&a[5];
int i;
printf("a[0] address: ");
printf("%0x\n",&a[0]);
for(i = 0; i < 10; i ++)
{
printf("&a[%d] addr: 0x%0x \n",i,&a[i]);
}
return 0;
}
执行结果
a[0] address: 12ff58
&a[0] addr: 0x12ff58
&a[1] addr: 0x12ff5c
&a[2] addr: 0x12ff60
&a[3] addr: 0x12ff64
&a[4] addr: 0x12ff68
&a[5] addr: 0x12ff6c
&a[6] addr: 0x12ff70
&a[7] addr: 0x12ff74
&a[8] addr: 0x12ff78
&a[9] addr: 0x12ff7c
Press any key to continue
你不能随意的给内存地址赋值!那是很危险的!如果你知道a[0]的地址,在以十六进制为输出地址的情况下,a[1]=a[0]+4。 你也可以写如下程序
#include <stdio.h>
int main()
{
int a[10]={11,12,13,14,15};
int a1=0x2000;
int n;
printf("when a[0] address is : 0x2000, If you want to quit, please input 999 \n");
printf("please select a[n] , n= ");
scanf("%d",&n);
while(n != 999)
{
printf("na[%d] addr: 0x%0x\n",n,a1+n*4);
printf("please select a[n] , n= ");
scanf("%d", &n);
}
return 0;
}
测试
when a[0] address is : 0x2000, If you want to quit, please input 999
please select a[n] , n= 0
na[0] addr: 0x2000
please select a[n] , n= 1
na[1] addr: 0x2004
please select a[n] , n= 2
na[2] addr: 0x2008
please select a[n] , n= 3
na[3] addr: 0x200c
please select a[n] , n= 4
na[4] addr: 0x2010
please select a[n] , n= 5
na[5] addr: 0x2014
please select a[n] , n= 6
na[6] addr: 0x2018
please select a[n] , n= 7
na[7] addr: 0x201c
please select a[n] , n= 8
na[8] addr: 0x2020
please select a[n] , n= 9
na[9] addr: 0x2024本回答被网友采纳