- 论坛徽章:
- 0
|
先贴这个Demo,代码写的不好,大家轻砸:
#include <stdio.h>
int main()
{
/*We Hope They Are All Together*/
int start = 0;
int i_am_start = 100;
float i_am_float = 3.1415926;
char i_am_char[20] = {34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53};
int end = 1;
int *pstart = &start;
int *pi_am_start = &i_am_start;
float *pi_am_float = &i_am_float;
char *pi_am_char = &i_am_char[0];
int *pend = &end;
printf("The Address of start is : ------%ld\n",&start);
printf("The Address of i_am_start is : ------%ld\n",&i_am_start);
printf("The Address of i_am_float is : ------%ld\n",&i_am_float);
printf("The Address of i_am_char is : ------%ld\n",&i_am_char[0]);
printf("The Address of end is : ------%ld\n",&end);
printf("The Address of pstart is : ------%ld\n",&pstart);
printf("The Address of pi_am_start is : ------%ld\n",&pi_am_start);
printf("The Address of pi_am_float is : ------%ld\n",&pi_am_float);
printf("The Address of pchar is : ------%ld\n",&pi_am_char);
printf("The Address of pend is : ------%ld\n",&pend);
printf("------------------------华丽的分割线------------------------\n");
printf("\n");
printf("------------------------华丽的分割线------------------------\n");
/*Display Datas In Memory We've Allocated*/
int count = 0;
char *p,*q,*r;
q = &i_am_char[0];
r = (char *)&i_am_float;
for(p = q;p < r;p++)
{
printf("The Value of p is:------%c,\t the Address of i_am_char[%d] is:------%ld\n",*p,count,p);
count++;
}
/*i_am_char[20]:What's Left Behind Me?*/
return 0;
}
|
我想查看这些变量在内存中的排列,问题是:我只申请了一个20个元素的数组,为什么数组和下一个变量之间有36个元素?打印出来的内容如图:
我用的是WinXP SP3+CodeBlocks,其中黄箭头之后的内容有什么另外的含义么?
贴一下各个变量的地址(在我机器上):
The Address of start is : ------2359148
The Address of i_am_start is : ------2359144
The Address of i_am_float is : ------2359140
The Address of i_am_char is : ------2359104
The Address of end is : ------2359100
The Address of pstart is : ------2359096
The Address of pi_am_start is : ------2359092
The Address of pi_am_float is : ------2359088
The Address of pchar is : ------2359084
The Address of pend is : ------2359080
麻烦大家了~~
[ 本帖最后由 -liupangzi- 于 2010-1-11 11:17 编辑 ] |
|