77问答网
所有问题
head=p1=(struct stu *)malloc(sizeof(struct stu)); 是什么意思,什么作用
如题所述
举报该问题
推荐答案 2012-05-18
malloc是C语言中的内存申请函数,上面这句完成几件事:
1.首先申请了一个大小为sizeof(struct stu)的内存块
2.内存地址强制类型转换为结构体指针(struct stu *)
3.用指针变量head和p1来保存这个内存地址
温馨提示:答案为网友推荐,仅供参考
当前网址:
http://77.wendadaohang.com/zd/WYIYNNp8v.html
其他回答
第1个回答 2012-05-18
neuodpo 说的对!
相似回答
...p
=(struct
stu
*)malloc(sizeof(struct
stu))
为
什么
新开辟的空间...
答:
那句语句的意思是 分配一个 大小为
结构体stu
的大小的空间,并把空间地址赋予p
c语言 问题
答:
struct student *
head=
NULL,*p1,*p2; //NULL要大写,你的P1,P2,
STU是
同级的,不能用stu *p1形式啊,只是P1是指向结点的指针,STU是是结构体变量.int n=0;
p1=(struct
student
*)malloc(sizeof(stu));
printf("input number and score:");scanf("%d%f", &p1->num,&p1->score); //你那有...
p
=(struct
student
*)malloc(sizeof(struct
student
))
答:
动态声明了一个student
结构体
的内存空间, 并将这块空间的指针保存给p变量
p1 =
p2
= (struct
student
*)malloc(sizeof(struct
student
));
这个语...
答:
新建一个student数据结构的对象,为其分配student结构所占用的内存空间。
sizeof(struct
student)为求该对象在内存中占用多少内存空间,让后用
malloc函数
分配同样大小的空间。将指针
p1,
p2指向该对象,即新分配出的空间。
c链表解释
答:
};int n; //全局计数器 struct student *creat(void) //创建比并填充数据,返回头指针地址 { struct student *
head;
//结构体指针 struct student *p1,*p2; //功能是:创建两个学生信息的结构体,其中p1用于用户输入信息,p2用于保存用户输入的信息 n=0
;p1=
p2
=(struct
student
*) malloc
...
我也是要写个C语言学生成绩编写的程序,但是老师给了一些东西 ,能不能...
答:
struct stu *p1,*p2,*head; int i,sum=0,n=0; printf("注意:当学生学号为 0 时输入结束\n\n");
p1=(struct
stu
*)malloc(sizeof(struct
stu));
/*得到学生信息*/
head=
p2
=p1
; do { printf("请输入学生的学号:"); gets(p1->num); if(strcmp(p1->num,"0")==0) break; printf("...
...
head=(struct
node
*)malloc(sizeof(struct
node
));
ptr=head;
是什
...
答:
malloc(
n)函数是动态分配n字节的内存空间。函数返回值是void型的所分配空间的首地址。你上面的head应该定义的是struct node类型的指针,所以把函数返回值赋给head要用(struct node*)进行强制类型转换。
sizeof(struct
node)是结构体node所需的字节数。head一般是作为表头指针,ptr
=head;
应该就是用ptr保留...
大家正在搜
mallocsizeof用法
sizeof struct
malloc sizeof
struct student
malloc与sizeof
malloc函数sizeof
数据结构mallocsizeof
sizeof(char)
sizeofstruct
相关问题
p1 = p2 = (struct student *)ma...
L=(linklist)malloc(sizeof(stru...
关于c语言链表的一个问题h->next=p1,p2->nex...
C语言怎么理解链表 p=(struct stu *)mall...
C语言 链表中malloc 用处: 比如head=(stru...
(struct Student*)malloc(sizeof...
p=(struct book *)malloc(size);...
ps=(stu*)malloc(sizeof(stu)); ...