上述定义中: struct关键词(保留字),表示定义一种结 构体类型。 strudent结构体名 结构体定义的一般形式: struct结构体名 成员表列}; 成员表列:类型标识符成员名 以上仅说明了定义一种类型的方法,尚未定 义变量 c語醒设计
上述定义中: struct ––– 关键词(保留字), 表示定义一种结 构体类型。 结构体定义的一般形式: struct 结构体名 {成员表列}; 成员表列:类型标识符 成员名 以上仅说明了定义一种类型的方法,尚未定 义变量。 strudent –––结构体名
如 struct exp 结构体名 i int times char flag 成员表列 float meter; c語醒设计
如:struct exp { int times; char flag; float meter; } 结构体名 成员表列
§10.2定义结构体变量
§10.2 定义结构体变量
三种方法可用来定义结构体变量: 、先定义结构体类型再定义结构体变量 例: struct student f int num; char name 20; char sex int age, float score char addr30]; struct student X1, X2 类型标识符 则x1,x2为 student结构型变量,x1,x2可存 放 student类型数据 c語醒设计
一、先定义结构体类型再定义结构体变量 三种方法可用来定义结构体变量: struct student x1 , x2 ; 则 x1 , x2为student 结构型变量,x1 , x2可存 放student类型数据。 例: struct student { int num; char name[20]; char sex; int age; float score; char addr[30]; } 类型标识符
在定义结构体类型的同时定义变量: 定义形式stuc结构体名 成员表列}变量名表列; 例 struct student i int num; char name 201 char sex Int age char addr[30 }x1,x2; c語醒设计
例: struct student { int num; char name[20]; char sex; int age; char addr[30]; } x1, x2; 定义形式 struct 结构体名 {成员表列} 变量名表列; 二、 在定义结构体类型的同时定义变量: