结构体变量简称为结构变量,它由结构类型定义,有三种定义方法。下面以定义结构类型 book 和结构变量mybook 、 storybook 为例说明之。 1. 先定义结构类型,再定义结构变量。 struct book /* 定义结构体类型 */ { char bookname[20]; float price; char publisher[20]; char author[10]; } ; struct book mybook, storybook; 用这种方法定义结构变量,是最常用的方法,但须注意不能省略关键字“ struct ”。还可以在定义结构变量的同时给它的成员赋初值。如: struct book /* 定义结构体类型 */ { char bookname[20]; float price; char publisher[20]; char author[10]; } ; struct book mybook = { “maths”, 24.7, “ 电子社 ”, “zhao” }, storybook; 则, mybook 变量的 price = 24.7 。 2. 定义结构类型的同时定义结构变量。 struct book /* 定义结构体类型 */ { char bookname[20]; float price; char publisher[20]; char author[10]; } struct book mybook, storybook; 3. 不定义结构类型,直接定义结构变量。 struct /* 不定义结构类型名 */ { char bookname[20]; float price; char publisher[20]; char author[10]; } struct book mybook, storybook; 需要说明的是,当某结构类型的成员又是另外一个结构类型时,称嵌套定义,其定义方法如下: struct brith_date { int month ; int day ; int year ; } ; struct { char name[10] ; char address[30]; char tel[12]; int age; struct data birthday; char sex[3]; } student_01 , employee ; 此例直接定义了 student_01 和 employee 两个变量,但是没有定义此结构体的名字,因此不能再定义与student_01 和 employee 同类的其它结构变量了!如下行定义是错误的: truct boy, girl;