方法二:在声明类型的同时定义变量 例如: struct student int num; char name[20]; char sex; int age; float score char addr 30]; student1,student2; 它的作用与第一种方法相同,即定义了两个struct student 类型的变量student1、student2
方法二:在声明类型的同时定义变量 例如: struct student { int num; char name[20]; char sex; int age; float score char addr[30]; }student1,student2; 它的作用与第一种方法相同,即定义了两个struct student 类型的变量student1、student2
方法二:在声明类型的同时定义变量 这种形式的定义的一般形式为: struct结构体名 { 成员表列 }变量名表列:
方法二:在声明类型的同时定义变量 这种形式的定义的一般形式为: struct 结构体名 { 成员表列 }变量名表列;
方法三:直接定义结构体类型变量 一 般形式为: struct { 成员表列 }变量名表列: 即不出现结构体名
方法三:直接定义结构体类型变量 一般形式为: struct { 成员表列 }变量名表列; 即不出现结构体名
对结构体类型的说明 关于结构体类型,有几点要说明: 1)类型与变量是不同的概念,不要混同: 只能对变量赋值、存取或运算,而不能对一个类 型赋值、存取或运算。 在编译时,对类型是不分配空间的,只对变量分 配空间。 2)对结构体中的成员(即“域”),可以单独使用, 它的作用与地位相当于普通变量。关于对成员的 引用方法见下一小节
对结构体类型的说明 关于结构体类型,有几点要说明: 1)类型与变量是不同的概念,不要混同: 只能对变量赋值、存取或运算,而不能对一个类 型赋值、存取或运算。 在编译时,对类型是不分配空间的,只对变量分 配空间。 2)对结构体中的成员(即“域”),可以单独使用, 它的作用与地位相当于普通变量。关于对成员的 引用方法见下一小节
对结构体类型的说明 3)成员也可以是一个结构体变量。如: struct date { int month; int day; int year; }: struct student { int num; char name[20]; char sex; int age; struct date birthday; char addr[30]; }student1,student2; num name sex age birthday addr month day year
对结构体类型的说明 3)成员也可以是一个结构体变量。如: struct date { int month; int day; int year; }; struct student { int num; char name[20]; char sex; int age; struct date birthday; char addr[30]; }student1,student2;