结构体、共用体、枚举类型及其它 例:结构体类型的声明或定义 自标要求 例 例struct student int num; 饼课提纲 char name[20]; struct date str int month; birthday 讲课内容 num name { int day, num namenonth diwhdayear int year, month day year )birthday; 课后作业 }st stu, 退出
目标要求 课后作业 讲课提纲 讲课内容 退出 例:结构体类型的声明或定义 结构体、共用体、枚举类型及其它 例 struct date { int month; int day; int year; }; struct student { int num; char name[20]; struct date birthday; }stu; num name birthday month day year 例 struct student { int num; char name[20]; struct date { int month; int day; int year; }birthday; }stu; num name birthday month day year
结构体、共用体、枚举类型及其它 ● 结构体变量的使用 自标要求 除对结构体变量赋值或作为参数传递给函数 等直接对一个结构体变量整体操作外,其它情况 下只能对结构体变量的各个成员分别引用,其引 讲课提纲 用形式为: 【格式】 结构体变量名,成员名 讲课内容 其中“.”叫做成员运算符,它在所 有的运算符中优先级最高。 课后作业 退出
目标要求 课后作业 讲课提纲 讲课内容 退出 除对结构体变量赋值或作为参数传递给函数 等直接对一个结构体变量整体操作外,其它情况 下只能对结构体变量的各个成员分别引用,其引 用形式为: 【格式】 结构体变量名 . 成员名 其中“ . ”叫做成员运算符,它在所 有的运算符中优先级最高。 结构体变量的使用 结构体、共用体、枚举类型及其它
●●● ctruct student 例 struct studen 例 struct student stu1.num=10; int num 例struct st { int num; 例 { int nun char name[20]; stul.score=85.5: 讲 char na char sex; nth if(stul=stu2) struct int age, () 1 { int r float score; M19,875 DaLian};(×) 讲 int d char addr[30]; birthday int y stul,stu2:; onth day year Stuz-stur, birthday; 课 stul,stu2; 退出
目标要求 课后作业 讲课提纲 讲课内容 退出 例 struct student { int num; char name[20]; char sex; int age; float score; char addr[30]; }stu1,stu2; stu1.num=10; stu1.score=85.5; stu1.score+=stu2.score; stu1.age++; 例 struct student { int num; char name[20]; char sex; int age; float score; char addr[30]; }stu1,stu2; printf(“%d,%s,%c,%d,%f,%s\n”,stu1); () stu1={101,“Wan Lin”,‘M’,19,87.5,“DaLian”}; () 例 struct student { int num; char name[20]; char sex; int age; float score; char addr[30]; }stu1,stu2; stu2=stu1; ( ) 例 struct student { int num; char name[20]; struct date { int month; int day; int year; }birthday; }stu1,stu2; num name birthday month day year stu1.birthday.month=12; 例 struct student { int num; char name[20]; char sex; int age; float score; char addr[30]; }stu1,stu2; if(stu1==stu2) . ()
结构体、共用体、枚举类型及其它 结构体变量的使用 结构体变量的一般用法。 自标要求 1.在定义结构体变量的同时,对结构体 变量初始化。 讲课提纲 例: struct stu 讲课内容 int num; char name[10]; 课后作业 float score stu1={10,Tom”,89}; 退出
目标要求 课后作业 讲课提纲 讲课内容 退出 结构体变量的一般用法。 1.在定义结构体变量的同时,对结构体 变量初始化。 例: struct stu { int num; char name[10]; float score }stu1={10,”Tom”,89}; 结构体、共用体、枚举类型及其它 结构体变量的使用