定义的一般形式: struct结构体 成员表列 }变量名表列;
• 定义的一般形式: struct 结构体 { 成员表列 }变量名表列;
3.直接定义结构类型的变量 定义的一般形式: struct 成员表列 }变量名表列;
3. 直接定义结构类型的变量 • 定义的一般形式: struct { 成员表列 }变量名表列;
说明 ·类型与变量是不同的概念 结构体中的成员可以单独使用,相当于普 通变量 成员也可以是一个结构体变量 如 birthday num name sex age addr month day year
说明 • 类型与变量是不同的概念 • 结构体中的成员可以单独使用,相当于普 通变量 • 成员也可以是一个结构体变量 如: num name sex age month day year birthday addr
struct date Rint month 3. int day, 4. int year; g 5. struct student 6. int num; 7. char name[20] 8. char sex 9. struct date birthday 10. char addr[30] 11.student1, student2
1. struct date 2. {int month; 3. int day; 4. int year;}; 5. struct student 6. {int num; 7. char name[20]; 8. char sex; 9. struct date birthday; 10.char addr[30]; 11.}student1,student2;
结构体变量的引用 1.只能对结构体变量中的成员分别访问 结构体变量名.成员名 tH: student. num=10010 不能整体访问! 如: printf((%d,%s,%c%d,%f,%s”, student1);
结构体变量的引用 1. 只能对结构体变量中的成员分别访问: 结构体变量名.成员名 如:student .num=10010; 不能整体访问!!! 如:printf(“%d,%s,%c,%d,%f,%s”,student1);