91结构体 912结构体变量的定义与初始化 2.结构体变量的初始化 【例95】结构体数组的初始化。 struct s i char num 8l, name 20, sex; float score; stu3l={{96060l"," Li ming","M',87.5}, t9606012,Zhang jiangguo", M, 79, 9606013"," Wang ping",F",90}; 元素的个数可以省略,根据赋初值时 结构体常量的个数确定数组元素的个数 2021-2-24
2021-2-24 11 元素的个数可以省略,根据赋初值时 结构体常量的个数确定数组元素的个数
91结构体 12 912结构体变量的定义与初始化 3.结构体变量的运算 ●用 sized运算符计算结构体变量所占内存空间 struct date t int year, month, day; 3: struct student i char num 8, name20], sex; struct date birthday float score a? sizeof(a)的结果为8+20+1+6+4=39 sizeof( struct student)的结果为39 2021-2-24
2021-2-24 12
91结构体 13 912结构体变量的定义与初始化 3.结构体变量的运算 ●同类型结构体变量之间的赋值运算 struct date f int year, month, day struct student t char num 8], name 20], sex; struct date birthday foat score: }a={"960601l"," Li ming","M,{1977,12,983},b,c; c- a 结构体变量之间进行赋值时,系统将按成员一一对应赋值 2021-2-24
2021-2-24 13
91结构体 14 912结构体变量的定义与初始化 3.结构体变量的运算 ●对结构体变量进行取址运算 struct date i int year, month, day; struct student i char num 8, name20], sex; struct date birthday; float score: a 对结构体变量a进行&a运算,可以得到a的 首地址,它是结构体类型指针 2021-2-24
2021-2-24 14
91结构体 15 912结构体变量的定义与初始化 ”是分量 4.结构体变量成员的引用 运算符,运算 级别最高。 结构体变量成员引用的一般形式: 结构体变量名.成员名 struct date 结构体变量的各个成员可 进行何种运算,由该成员 f int year, month, day; j 的数据类型决定 struct student I char num[8], name(20], sex; a birthday year struct date birthda a birthday. month float score: a birthday day a 结构体变量a的各成员可分别表示为anum aname、a.sex、a. birthday、a. score 2021-2-24
2021-2-24 15 结构体变量a的各成员可分别表示为a.num、 a.name、a.sex、a.birthday、a.score a.birthday.year a.birthday.month a.birthday.day