一、如何定义结构体和初始化结构体
1.定义结构体
struct book {
char title[MAXTITL];
char author[AXAUTL];
float value;
} library;
注解:此处定义了一个名字为 library 的struct book结构体,如果要继续定义新的结构体,如:
struct book library2; // 这样便定义了一个新的strut book类的结构体 library2
2.初始化结构体
两种方式,一种在定义结构体时初始化,另一种利用结构体成员运算符进行引用初始化。
二、如何引用该类结构体成员
在定义了 library 和 library2 两个结构体后,若想要访问其内部成员,应该使用结构体成员运算符点(.)就可以,例如:
library.value = 9; library.title
三、如何使用结构体指针访问结构体成员
1、结构体指针的定义和初始化
struct book *it;
it = &library;
2、使用结构体指针it访问结构体成员变量
it->value = 9;
it->title;