c程序设计第9章自定义数据类型内容摘要:

u[i].name,stu[i].aver)。 } 10 指向结构体变量的指针 A0901 : include struct student{ int num。 char name[20]。 float score1。 float score2。 float score3。 float aver。 }stu={001,zhang3,80,88,75}。 struct student *p=amp。 stu。 stu. aver=stu. score1+ +。 stu. aver /=3。 printf(%5d%20s%\n, , , )。 001 “zhang3” 80 88 75 P p p p p p (*p). (*p). (*p). 结构体类指针变量的定义: 结构体类型名称 *指针变量名 通过指针变量引用成员: 1) 结构体类指针变量名 成员名 (常用) 2) (*结构体类指针变量名 ).成员名 11 指向结构体数组的指针 A0901 : include struct student{ int num。 char name[20]。 float score1。 float score2。 float score3。 float aver。 }。 stu[3]={{001,zhang3,80,88,75},{002,li4,90,83,84}, {003,wang5,50,62,65}}。 struct stud *p=stu。 for(p=stu。 pstu+3。 p++) { paver=pscore1+pscore2+pscore3。 paver /=3。 } for(p=stu。 pstu3。 p++) printf(%5d%20s%\n, pnum, pname, paver)。 84 83 90 “ li4” 002 75 88 80 “zhang3” 001 stu[0] stu[1] stu[2] P p++ 指向数组中的下一个元素 12 用指针构成链表 75 88 80 “zhang3” 001 002 84 83 90 “ li4” 59 65 62 50 wang5 003 指针 指针 指针 1249 1356 1475 新 增加 一个学生。 数组不能动态定义。 新增信息存储单元不连续 每个结构中的最后一个是指针, 指向下一个节点的首地址,形成链式结构 struct student{ int num。 char name[20]。 float score1。 float score2。 float score3。 float aver。 }。 struct student *next。 不行。 链表:可以使物理上不连续的存储单元在逻辑上连续访问 13 构建链表 A0902例 建立如下链表,由 3个学生数据的结点组成。 输出各结点中的数据,并计算学生成绩的平均值。 next 001 002 90 004 85 next next struct student { int num。 float score。 struct stu。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。