1.结构体的标准形式:
struct 结构体名
{
结构体成员列表;
}
例如:
struct student
{
int num;
char nam[16];
float score;
}
2.结构体的赋值方式
(1)struct student stu1 ;
stu1.num = 1000;
strcpy (stu1.name,“zhangsan”);
stu1.score = 98;
(2)
struct student stu2 = {101,"xiaoming",99};
(3)
struct student
{
int num;
char nam[16];
f loat score;
}stu 5 = {1002,"lihua",89}
3.结构体数组
基本形式:
struct 结构体名 数组名 [元素个数]
struct student stu[3]
4.结构体数组赋值代码实现
#include<stdio.h>
struct stu
{
char name[16];
int age;
float score;
};
int main()
{
struct stu s[3] = {{"xiaoming",5,88},{"xiaohong",5,89},{"xiaobai",5,90}};
int i;
for (i=0;i<3;i++)
printf("%s %d %f\n",s[i].name,s[i].age,s[i].score);
return 0;
}