第章结构体类型与共用体类型 (3)平面上的点 struct point2 { float x;/横坐标* float y;/*纵坐标* 如考虑空间中的点,可作如下定义 struct point3 { float x;/*X坐标*/ float y;:/*Y坐标* float z;/*Z坐标*
第 9章 结构体类型与共用体类型 (3) 平面上的点: struct point2 {float x; /*横坐标*/ float y; /*纵坐标*/ }; 如考虑空间中的点, 可作如下定义: struct point3 {float x; /*X坐标*/ float y; /*Y坐标*/ float z; /*Z坐标*/ };
第章结构体类型与共用体类型 (4)日期,包括年、月、日 struct date Int year;/*年 month;/*月* day;/*日* 如考虑时间,可作如下定义: struct time int hh;/*时 Int mm;/*分* Int ss;/*秒*/
第 9章 结构体类型与共用体类型 (4) 日期, 包括年、 月、 日: struct date {int year; /*年*/ month;/*月*/ day; /*日*/ }; 如考虑时间, 可作如下定义: struct time {int hh; /*时*/ int mm; /*分*/ int ss; /*秒*/ };
第章结构体类型与共用体类型 (5)复数: struct complex { float re;/*实部*/ float ie;/*虚部*
第 9章 结构体类型与共用体类型 (5) 复数: struct complex {float re; /*实部*/ float ie; /*虚部*/ };
第章结构体类型与共用体类型 (6)三角形 struct S]x float a,b,c;/三边*}
第 9章 结构体类型与共用体类型 (6) 三角形: struct sjx {float a, b, c; /*三边*/};
第章结构体类型与共用体类型 912结构体变量的定义 1)先定义结构体类型,再定义结构体变量 形式为 ① struct标识符 {成员表} ② struct标识符变量表; 例如,对以上定义的结构体类型,我们可以定义如下 些结构体变量 struct student zhang;/*张同学情况* struct person p[100]:/*100个人的数据* struct point2pl,p2;/*平面上的两个点* struct point3pol,po2;/*空间上的两个点*
第 9章 结构体类型与共用体类型 9.1.2 结构体变量的定义 (1) 先定义结构体类型, 再定义结构体变量。 形式为: ① struct {成员表}; ② struct 标识符 变量表; 例如,对以上定义的结构体类型,我们可以定义如下 一些结构体变量: struct student zhang; /*张同学情况*/ struct person p[100];/*100个人的数据*/ struct point2 p1,p2; /*平面上的两个点*/ struct point3 po1,po2;/*空间上的两个点*/