- 论坛徽章:
- 0
|
本帖最后由 zhuqing_739 于 2010-08-23 16:02 编辑
不是说你的结构,是说malloc分配的内存地址
hellioncu 发表于 2010-08-23 15:44
看下面这段改过的程序就知道不是按8对齐的了!- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- typedef struct student
- {
- char name[11];
- float score;
- struct student *node;
- }STUDENT;
- int main(int argc, char *argv[])
- {
-
- STUDENT *p1, *p2, *p3;
- printf("the size of STUDENT is %d\n",sizeof(STUDENT));
- p1 = (STUDENT *)malloc([size=5]4[/size]);
- if (NULL == p1)
- {
- printf("malloc error");
- return 1;
- }
- printf("the address is %p\n",p1);
- p2 = (STUDENT *)malloc([size=5]4[/size]);
- if (NULL == p2)
- {
- printf("malloc error");
- return 1;
- }
- printf("the address is %p\n",p2);
- p3 = (STUDENT *)malloc([size=5]4[/size]);
- if (NULL == p3)
- {
- printf("malloc error");
- return 1;
- }
- printf("the address is %p\n",p3);
- free(p1);
- p1 = NULL;
- free(p2);
- p2 = NULL;
- free(p3);
- p3 = NULL;
-
-
- return 0;
- }
复制代码 看一下输出结果:
the size of STUDENT is 20
the address is 0x804a008
the address is 0x804a018
the address is 0x804a028 |
|