很久没用结构体了,今天给自己总结一下:
第一种是
struct string
{
char name[8];
int age;
float wage;
} person;
第二种
struct string
{
char name[8];
int age;
float wage;
};
struct string person;
person为名字为string的结构体变量。
第二种结构体指针
struct string
{
char name[8];
int age;
float wage;
} *person;
结构体指针
结构体指针访问结构成员可表示为:
person->age=9;
strcpy(student->name,"dfff");
等价于(*person).age;
当使用结构体对结构指针初始化的时候,需要分配整个结构长度的字节空间:
person=(strcuct string*)malloc(sizeof(struct string));
结构变量明person不是指向结构的地址,指向成员的首地址需要&person。