p7 struct and union
struct StudentRec //①声明结构体类型StudentRec
{
char StuNum[20]; //②定义结构体的成员变量
char StuName[20]; //② 1.Dot “.” is called the member selection operator.
2. After the struct type declaration, the various members can
be used in your program only when they are preceded by a struct variable name and a dot.
int Score1; //②
int Score2; //②
int Admit; //②
} ;
//用结构体类型定义变量stu1和stu2
struct StudentRec stu1, stu2;
//访问结构体变量stu1中的成员
strcpy(stu1.StuNum, "0001");
strcpy(stu1.StuName, "Zhangsan");
stu1.Score1 = 90;
stu1.Score2 = 100;
stu1.Admit = 1;
printf( "%s %s %d %d %d\n",
stu1.StuNum, stu1.StuName,
stu1.Score1, stu1.Score2, stu1.Admit );
struct studentRec* pStu;
strcpy( pStu->num, “1000” );
strcpy( pStu->num, “Linda”;
pStu->Sccore1 =89;