结构体、指针
①struct StudentRec //①声明结构体类型StudentRec
{
char StuNum[20]; //②定义结构体的成员变量
char StuName[20]; //②
int Score1; //②
int Score2; //②
int Admit; //②
} ;
//用结构体类型定义变量stu1和stu2
struct StudentRec stu1, stu2
strcpy(stu1.StuNum, "0001");
strcpy(stu1.StuName, "Zhangsan"); // Dot “.” is called the member selection operator。。。。用在非指针那里
stu1.Score1 = 90;
stu1.Score2 = 100;
stu1.Admit = 1;
②struct StudentRec
{
char StuNum[20];
char StuName[20];
int Score1;
int Score2;
int Admit;
} ;
int main()
{
struct studentRec Stu;
struct studentRec* pStu;
pStu = &Stu;
strcpy( Stu.num, “1000” ); //.用在非指针类型
strcpy( Stu.name, "Linda" );
Stu.Score1 = 89;
//or
strcpy( pStu->num, “1000” ); //->用在指针类型。两者等价
strcpy( pStu->num, “Linda”;
pStu->Sccore1 =89;
}
③struct students
{
char StuNum[20];
char StuName[20];
int Score1;
int Score2;
bool Admit;
} stu1, stu2; //定义结构体变量stu1,stu2
④设指针
struct NODE {
int element; // 存放堆栈的元素
struct NODE* link; // 指向下一个结点的指针
};