解释下这句C代码

来源:百度知道 编辑:UC知道 时间:2024/07/08 01:26:28
struct student
{
};
struct student *p1=NULL;
p1=(struct student *)malloc(sizeof(struct student));
哪位兄弟帮我解释下 谢谢
假如我在结构体里定义了一个数组
如struct student
{
int score[3];
}
struct student *p1=NULL;
p1=(struct student *)malloc(sizeof(struct student));
printf("输入每科分数:");
后面的怎么写啊 才能用键盘输入每科分数啊

定义结构体 student
用student定义结构体p1,并不赋初值
为P1开辟堆栈并把首地址赋值给p1

给学生定义的一个空结构,最好一句是给指针p1申请结点,存储你想要输入的值

struct student *p1=NULL; P1指针初始化为0
P1申请内存 p1=(struct student *)malloc(sizeof(struct student));

p1=(struct student *)malloc(sizeof(struct student));

动态分配一段能存放一个struct student类型变量的存储空间,由p1指向这段空间的地址。