先声明结构体类型在定义变量名 如上面已定义的结构类型 struct student 可以用它来定义变量 变量名 struct student studentI student2 注意 定义标准类型变量和定义结构体类型变量不同 前者类型是已知的(如int,foat),而后者要先定义类型后 定义变量 人们通常用一个符号常量代表一个结构体类型 #define student struct student
如上面已定义的结构类型struct student, 可以用它来定义变量: struct student student1, student2 变量名 注意: 定义标准类型变量和定义结构体类型变量不同 前者类型是已知的(如int,float),而后者要先定义类型后 定义变量 人们通常用一个符号常量代表一个结构体类型 #define STUDENT struct student 先声明结构体类型在定义变量名
在声明类型的同时定义变量 struct student fint num, char name[20] char sex Int age; float score, char addr301 studenti, student2 变量名列表
struct student {int num; char name[20]; char sex; int age; float score; char addr[30]; }student1,student2; 变量名列表 在声明类型的同时定义变量
定义的一般形式为: struct结构体名 成员表列 }变量名表列
定义的一般形式为: struct 结构体名 { 成员表列 } 变量名表列
直接定义 结构体类型变量 struct fint num; char name 201 char sex, int age float score char addr 301 3 student, student2
struct {int num; char name[20]; char sex; int age; float score; char addr[30]; }student1,student2; 直接定义 结构体类型变量
说明 1.类型与变量是不同的,变量可以赋值,存取和运算。对类 型是不分配空间的 2对结构体中的成员,可以单独使用,它的作用与地位相当 与普通变量 3成员也可以是一个结构体变量。如: Struct student struct date nt num f int month; char name 20; int day; char sex: int age; Int year struct date birthdays char addr 30; 4成员名可以与程序中 3 student1, student2 的变量名相同
说明: 1.类型与变量是不同的, 变量可以赋值,存取和运算。对类 型是不分配空间的. 2.对结构体中的成员,可以单独使用,它的作用与地位相当 与普通变量. 3.成员也可以是一个结构体变量。如: struct date { int month; int day; int year; } 4.成员名可以与程序中 的变量名相同 Struct student {int num; char name[20]; char sex; int age; struct date birthday; char addr[30]; } student1,student2;