结构体是一种数据类型(像int、char、flaot是数据类型一样),可以用它定义变量。
用结构体类型定义变量的方式有三种:
一、先定义结构体类型,再定义变量
一般形式:struct 结构体名
{
类型标识符 成员名;
类型标识符 成员名;
…………….};
struct 结构体名 变量名表列;
例、struct student
{
int num;
char name[20];
char sex;
int age;
float score;
char addr[30];
};
struct student student1, student2;
结构体变量中的各成员,在内存中顺序存放。结构体变量所占内存大小用运算符sizeof计算。
例、printf(" %d %d \n",sizeof(struct
student), sizeof(student1));