第十一章结构体和共用体本章节介绍用户如何自定义数据类型定义类型typedef语句结构体的定义方式本章内容目的与要求如何自定义结构体类型定义(typedef)31结构体32第十一章结构体和共用体共用体32(不做要求)类型定义(typedef)31结构体32第十一章结构体和共用体共用体321.类型定义(typedef)功能:将已有的类型标识符定义成新的类型标识符;格式:typedef系统类型标识符用户自定义标识符说明:系统类型标识符为int,float,char;用户自定义标识符类型定义(typedef)例:①typedefintINTERGER;INTEGERi,j;②typedeffloatREAL;REALa,b;③typedefcharCHARACTER;CHARACTERch1,ch2;例:④typedefcharSTRING[80];STRINGS;chars[80]⑤typedeffloat*PFLOAT;PFLOATp1,p2;float*p1,*p2;例:⑥typedeffloatREAL;typedefREALfudian;fudiana,b;floata,b;1.类型定义(typedef)功能:将已有的类型标识符定义成新的类型标识符;格式:typedef系统类型标识符用户自定义标识符说明:系统类型标识符为int,float,char;用户自定义标识符注意:typedef不能创造新数据类型;typedef定义的新类型名不能与关键字重复类型定义(typedef)例:typedefintfloat;typedefintwhile;类型定义(typedef)31结构体32第十一章结构体和共用体共用体321.结构体定义:将不同数据类型(int,float,char)组合成一个整体;1.类型定义(typedef)studentnumbernameagesexscoreaddress字符字符整型字符单精度字符结构体类型名结构体成员studentnumbernameagesexscoreaddress字符字符整型字符单精度字符1.structstudent2.{charnumber[5];3.charname[12];4.intage;5.charsex[6];6.floatscore;7.charaddress[31];};numbernameagebirthdaysexscoreaddressyearmonthday字符字符整型整型整型整型字符单精度字符numbernameagebirthdaysexscoreaddress=student型yearmonthdaydate型+structdatebirthday;student型numbernameagebirthdaysexscoreaddressyearmonthday字符字符整型字符单精度字符date型structdate{intyear;intmonth;intday;};structstudent{charnumber[5];charname[12];intage;structdatebirthday;charsex[6];floatscore;charaddress[31];}student1,student2,student3;student型numbernameagebirthdaysexscoreaddressyearmonthday字符字符整型字符单精度字符date型structstudent{charnumber[5];charname[12];intage;structdate{intyear;intmonth;intday;}birthday;charsex[6];floatscore;charaddress[31];}student1,student2,student3;student型numbernameagebirthdaysexscoreaddressyearmonthday字符字符整型字符单精度字符date型structstudent{charnumber[5];charname[12];intage;structdate{intyear;intmonth;intday;}birthday;charsex[6];floatscore;charaddress[31];}structstudentstudent1,student2,student3;studentnumbernameagesexscoreaddress字符字符整型字符单精度字符structstudent{charnumber[5];charname[12];intage;charsex[6];floatscore;charaddress[31];}student1={“1001”,“wangjun”,21,“women”,90.5,“beijingstreet256”},student2={“1002”,“lisi”,22,“man”,92.5,guangzhou};3.结构体变量的引用studentnumbernameagebirthdaysexscoreaddressyearmonthday字符字符整型整型整型整型字符单精度字符3.结构体变量的引用structstudentstudent1,student2,student3;student1.number=“10001”;student2.age=22;student3.birthday.month=5;