2、不能将一个结构体变量作为一个整体进行输入输出; printf("ood %s%f, stuD);x scanf(%od%s%f, &stuD);x 只能对结构体中的各个成员分别进行输入输出。 printf( %d%s%f stul num, stul name, stul score) scanf( %od",&stul num; gets(stul name); struct student struct date i int num; char name[20 stu birth- year=2002 int year: char sex stu birth month= =4; int month, struct date birth; stu birth day=19 int day, char addr[ 30: , stu
2、不能将一个结构体变量作为一个整体进行输入输出; printf("%d%s%f", stu1); × scanf("%d%s%f", &stu1); × 只能对结构体中的各个成员分别进行输入输出。 printf("%d%s%f", stu1.num, stu1.name, stu1.score); scanf("%d", &stu1.num); gets(stu1.name); struct date { int year; int month; int day; }; struct student { int num; char name[20]; char sex; struct date birth; char addr[30]; }stu; stu.birth.year=2002; stu.birth.month=4; stu.birth.day=19;
3、相同类型的结构体变量可以进行整体赋值 stu2 num=stu l num stu2=stu 1. strcpystu2. name, stul name); stu2 score=stu l score; 因此,结构体类型变量可以作为函数的参数。 void fun (struct student stu: fun (stu1) 4、成员变量可以像普通变量一样进行各种运算(根据其类型决定可 以进行的运算) sum=stul score+stu2 score; stul age++i 5、可以引用结构体变量成员的地址,也可以引用结构体变量的地址 scanf("%d"&stul num): printf(%x",&stul 心U
3、相同类型的结构体变量可以进行整体赋值 stu2=stu1; stu2.num=stu1.num; strcpy(stu2.name, stu1.name); stu2.score=stu1.score; 因此,结构体类型变量可以作为函数的参数。 void fun(struct student stu); fun(stu1); 4、成员变量可以像普通变量一样进行各种运算(根据其类型决定可 以进行的运算) sum=stu1.score+stu2.score; stu1.age++; 5、可以引用结构体变量成员的地址,也可以引用结构体变量的地址 scanf("%d", &stu1.num); printf("%x", &stu1);
6、可以定义与结构体成员相同名字的变量,它们之间不会发 生混乱。 struct student stu: int age, year; stu age= 20 stu birthday year =1980 age=24 year=2000; 心U
6、可以定义与结构体成员相同名字的变量,它们之间不会发 生混乱。 struct student stu; int age, year; … stu.age = 20; stu.birthday.year = 1980; …… age = 24 ; year = 2000 ;
3结构体变量的初始化 在定义结构体变量的同时,可以进行初始化。 struct student i int num; char name [20] float score }stu1={15001,"宋红",89.5}; struct student stu2={15001,"宋红",89.5}; struct student stu3: stu3¥15001,“宋红",895} 这是赋值,错误 心U
3 结构体变量的初始化 在定义结构体变量的同时,可以进行初始化。 struct student { int num; char name[20]; float score; }stu1={15001, "宋红", 89.5}; struct student stu2={15001, "宋红", 89.5}; struct student stu3; stu3={15001, "宋红", 89.5}; 这是赋值,错误