关于结构体地址问题
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <malloc.h>
struct node1{
char str[15]; /*必须要换成*str*/
int i;
};
void main()
{
char *string;
struct node1 *p;
printf("%o\n",string);
printf("%o\n",p->str);
printf("%o\n",p->i);
p=(struct node1 *)malloc(sizeof(struct node1));
if(p==NULL)
{printf("Can't get momery.\n");exit(1);}
scanf("%s",string);
printf("%o\n",string);
printf("%o\n",p->str);
printf("%o\n",p->i);
getch();
}
在TC环境下的运行结果:
6262
3173
40524
asdf(随便输的)
6262
6410
177520
这里有个疑问:为什么string前后的地址是一样的?而p->str和p->i的地址前后不一致?
还有str和i在一个结构体里面,它们的地址为什么隔这么远,而不是挨着的呢?不理解。
问题问题有点傻。请指教。谢谢!