|

楼主 |
发表于 2004-8-21 15:06:30
|
显示全部楼层
- [color=crimson][SIZE=4]#include<stdio.h>
-
- struct stu
- {
- char *name;
- char sex;
- int age;
- float score;
- } *ps;
-
- main()
- {
- ps=(struct stu *)malloc(sizeof(struct stu));
-
- ps->name="shellon";
- ps->sex='M';
- ps->age=21;
- ps->score=68;
-
- printf("name is %s\nsex is %c\nthe age is %d\nThe score is %f\n",ps->name,ps->sex,ps->age,ps->score);
-
- free(ps);
-
- putchar('\n');
-
- printf("name is %s\nsex is %c\nthe age is %d\nThe score is %f\n",ps->name,ps->sex,ps->age,ps->score);
- }[/size][/color]
复制代码
这里释放了内存后,再printf的话,name的输出就没有,其他还有,这什么原因呢 ?? 为什么sex,age,score还能正常输出呢 ?
name is shellon
sex is M
the age is 21
The score is 68.000000
name is (null)
sex is M
the age is 21
The score is 68.000000 |
|