定义结构体
struct student
{
int number;
char name[4];
char sex;
float grade;
}; //敲黑板!大括号外还应加分号!
struct student a={1,"LiHua","man",100}; //等同于a.number=1;a.name="LiHua";a.sex="man";a.grade=100;
结构体内的项都用逗号隔开,字符用单引号,字符串用双引号
定义结构体数组
struct student
{
int number;
char name[4];
char sex;
float grade;
}; xuesheng[3]={{1,"LiHua",man,90},{2,"XiaoMing",man,80},{3,"XiaoHong",woman,100}}; //敲黑板!大括号里套大括号,里面的大括号用逗号隔开
可写作:
xuesheng[0].number=1; xuesheng[0].name=“LiHua”; xuesheng[0].sex=man; xuesheng[0].grade=90;
xuesheng[1].number=2; xuesheng[1].name=“XiaoMing”; xuesheng[1].sex=man; xuesheng[1].grade=80;
xuesheng[2].number=3; xuesheng[2].name=“XiaoHong”; xuesheng[2].sex=woman; xuesheng[2].grade=100;
注意结构体后有一个“.”
结构体变量&函数变量
定义的函数变量都要是结构体类型!
eg.struct student youxiu;
struct student pingjunfen(struct student a[ ]);
结构体变量&指针变量
定义的指针变量都要是结构体类型!
eg.struct student *p;