7.2.2结构体变量的定义、引用与初始化 19
for (i=1; i<=5; i++) printf("%s:%d\n",list[i].name,list[i].count);
printf("%s:%d\n",list[0].name,list[0].count); }
2019/10/28
7.2 结构体类型
1. 结构体类型变量的定义
直接定义结构体类型变量 struct
{ 成员定义表; }变量名表;
例如:struct { char num[8],name[20],sex; int age; float score; }st[30], a, b, c;
2019/10/28
7.2.2结构体变量的定义、引用与初始化 11
c = a;
结构体变量之间进行赋值时,系统将按成员一一对应赋值。
2019/10/28
7.2.2结构体变量的定义、引用与初始化 15
3. 结构体变量的运算
对结构体变量进行取址运算
struct date { int year, month, day;}; struct student { char num[8], name[20], sex;
}a;
a.birthday.year a.birthday.month a.birthday.day
结 构 体 变 量 a 的 各 成 员 可 分 别 表 示 为 a.num、 、a.sex、a.birthday、a.score
2019/10/28
7.2.2结构体变量的定义、引用与初始化 17
list[n].count++; /* 有效票,则相应候选人计票成员加1 */