第11章第3节 ANS新标准:具有相同结构的两个结构体变量可整体赋值 stu2=s1;当于 stu2.num← stulnum stu2.name←stul.name stu2 score stul score 4.成员又是结构体类型—只能引用最低级别的成员 例: struct score float english float math struct student Bint num: char name 301; char sex int age struct score exame: 3 stul, stu2; scanf(%d, %f, %f, &stul num, &stul exame. english, &stul exame. math); ave=(stul exame english+stu2 exame. math)/2.0
第11章第3节 ANS新标准:具有相同结构的两个结构体变量可整体赋值 stu2=stu1; stu2.num ←stu1.num stu2.name ←stu1.name ...... stu2.score ←stu1.score 相当于 4. 成员又是结构体类型——只能引用最低级别的成员 例: scanf(“%d,%f,%f”, &stu1.num, &stu1.exame.english, &stu1.exame.math); ... ave= (stu1.exame.english+stu2.exame.math)/2.0; struct score {float english; float math;}; struct student {int num; char name[30]; char sex; int age; struct score exame; } stu1,stu2;
§11.4结构体变量的初始化 第11章第4节 在定义结构体变量时赋初值 例1分开定义时赋初值 struct student 注意: f int num; char name 303; 初始值的顺序、类型与成员要一致 char sex; int as m1=(1001, "Liming", 'M, 18, 90.07 float se struct student stul 例2同时定义时赋初值 struct student f int num; char name 301; char sex int age: float score;}stul={1001,“ Liming”,M’,18,90.0}; 例3直接定义时赋初值 struct d int num; char name 3( char sex int age: float score; stul=(1001,Liming ", M,, 18, 900j;
§11.4 结构体变量的初始化 第11章第4节 在定义结构体变量时赋初值 struct student { int num; char name[30}; char sex; int age; float score;}; struct student stu1={1001,“Liming”,’M’,18, 90.0} 例1 例2 struct student { int num; char name[30}; char sex; int age; float score;} stu1={1001,“Liming”,’M’,18, 90.0}; 例3 struct { int num; char name[30}; char sex; int age; float score;} stu1={1001,“Liming”,’M’,18, 90.0}; 注意: 初始值的顺序、类型与成员要一致 分开定义时赋初值 同时定义时赋初值 直接定义时赋初值