结构体
struct 结构体名{} 变量名;
结构体变量:
struct person{
char *name;
int age;
float score;
} student;
成员的获取和赋值
//Members of the acquisition and assignment
student.name="taoshihan";
student.age=30;
student.score=100;
printf("name=%s \n",student.name);
C语言结构体数组
struct stu{
char *name;
int age;
float score;
} classes[5];
遍历结构体数组
struct people{
char *name;
int age;
float score;
} d[]={
{"taoshihan",20,100},
{"lisi",30,90}
};
int len=sizeof(d)/sizeof(d[0]);
printf("d length=%d \n",len);
for(int i=0;i<len;i++){
printf("loop...%s,%d,%.1f \n",d[i].name,d[i].age,d[i].score);
}
C语言结构体和指针
struct 结构体名 *变量名;
struct person1{
char *name;
int age;
float score;
}