C该结构变化 struct typedef



这几天看代码,看到若干类型的结构,例如下列结构声明:

struct    book{

   string name;

   int price;

   int num;

};

此种结构定义结构变量的格式例如以下:

struct    book      student;


 struct      book{

   string name;

   int price;

   int num;

}student;

此种形式代表声明结构的过程和定义结构变量的过程被合并成一步


typedef    struct  (book){   //book可省略

   string name;

   int price;

   int num;

}student;

typedef的作用是为一个已存在的类型创建一个名字,故此种结构的结构体定义变量的格式是:student    a;



个人觉得最后一种在书写上比較方便。当你在程序中大量定义结构体变量时。



版权声明:本文博主原创文章,博客,未经同意不得转载。

posted @ 2015-09-11 17:12  yxwkaifa  阅读(141)  评论(0编辑  收藏  举报