结构体、共同体和枚举类型
结构体
定义:
将不同种类型的数据有序地组合在一起,构造出一个新的数据类型,这种形式称为结构体。
结构体是多种类型组合的数据类型。
struct 结构体名
{ 成员列表 };
struct student
{ i
int num;
char name[20];
char sex;
char addr[30];
};
定义结构体类型变量的方法
一、先定义结构体类型再定义变量名
truct student
{ int num;
char name[20];
char sex;
int age;
float score;
char addr[30];
};
结构体类型只是一种数据类型,不占内存空间,只有定义结构体类型变量时才开辟内存空间。
# define STUDENT struct student
STUDENT
{
int num;
char name[20];
char sex;
int age;
float score;
char addr[30];
};
STUDENT student1,student2;
凡是STUDENT的地方都用struct student 机械替换。