结构体与指针ppt课件.ppt

结构体与指针ppt课件.ppt

ID:58687266

大小:636.50 KB

页数:70页

时间:2020-10-04

结构体与指针ppt课件.ppt_第1页
结构体与指针ppt课件.ppt_第2页
结构体与指针ppt课件.ppt_第3页
结构体与指针ppt课件.ppt_第4页
结构体与指针ppt课件.ppt_第5页
资源描述:

《结构体与指针ppt课件.ppt》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、第九章结构体与指针学习目标掌握结构体与联合体的概念、语法和应用掌握指针的概念和应用学会用指针访问数组、结构体和函数掌握动态存储分配方法掌握单链表的概念和应用9.1结构体结构体的意义将不同数据类型的数据对象组织在一起结构体的应用结构体类型声明与结构体变量声明结构体类型的嵌套结构体变量的整体赋值与逐成员赋值结构体作为函数参数:发生整个结构体的值拷贝操作结构体嵌套示例structDate{intyear;intmonth;intday;};structChild{floatheight;floatweight;Dateb

2、irthday;chargender;};structChilda;a.height=0.99;a.birthday.year=2000;a.birthday.month=2;a.birthday.day=14;if(a.height>=1.00&&a.birthday.year<=1999){printf(“儿童上车须买半票”);}结构体应用示例从键盘读取若干0-5岁儿童的身高、体重、年龄、性别,然后统计出指定年龄段的儿童的最高、最低身高和平均身高,并输出相应个体的全部信息,儿童的总数由键盘输入,需要统计的年

3、龄段由键盘输入#include#definekMAXCHILDREN100structChild{floatheight;floatweight;intage;chargender;};结构体应用示例voiddisplayChild(structChildchild1){printf(“Age%d“,child1.age);printf(“Gender%c“,child1.gender);printf(“Height%f“,child1.height);printf(“Weight%f

4、“,child1.weight);}structChildinputChild(){structChildchild1;printf(“Age:“);scanf(“%d“,&child1.age);getchar();printf(“Gender:“);scanf(“%c“,&child1.gender);printf(“Height:“);scanf(“%f“,&child1.height);printf(“Weight:“);scanf(“%f“,&child1.weight);returnchild1;}

5、结构体应用示例intmain(){structChildsurveyset[kMAXCHILDREN],tallest,shortest;inti,n,age,count;floatsum=0;printf(“Numberofchildren:“);scanf(“%d“,&n);for(i=0;i

6、age>=0){tallest.height=0;shortest.height=2;sum=0;count=0;for(i=0;itallest.height)tallest=surveyset[i];if(surveyset[i].height

7、用示例printf(“Thetallest:“);displayChild(tallest);printf(“Theshortest:“);displayChild(shortest);printf(“Theaverageheight:%f“,sum/count);printf(“Entertheageofchildrenyouwanttocount:“);scanf(“%d“,&age);}//while(age>=0)}结构体指针指向结构体变量的指针声明格式:struct结构体名*结构体指针变量名;

8、例:structChild{…};structChild*p;structChilda={0.83,30.0,5,‘M’};p=&a;结构体成员的引用一般例:(*p).height=0.83;或p>height=0.83;嵌套引用例:(*p).birthday.year=2000;或p>birthday.year=2000;9.2指针指针的意义与作用指针

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。