1.结构体声明的三种形式
1.1先声明,后定义
struct book
{
char title[50];
char author[50];
float price;
int page;
};
-创建结构体变量
struct book Shot;
1.2 声明与定义放在一起
struct book
{
char title[50];
char author[50];
float price;
int page;
} Shot;
1.3 声明与定义放在一起,省略结构体名
struct
{
char title[50];
char author[50];
float price;
int page;
} Shot;
2. 进阶-使用typedef定义结构体类型
2.1
typedef struct book
{
char title[50];
char author[50];
float price;
int page;
} BOOK_T;
其实可以这样分开写,更容易理解:
struct book
{
char title[50];
char author[50];
float price;
int page;
} ;
typedef struct book BOOK_T;
2.2
如果省略结构体名,可以采用如下写法,并且不能分开写
typedef struct
{
char title[50];
char author[50];
float price;
int page;
} BOOK_T;
typedef并没有创建新的类型,它只是为已有的类型增加了一个方便使用的标签。