C++ 结构体(二)

来源:互联网 发布:java实现AES 编辑:程序博客网 时间:2024/06/02 23:39

1.用typedef定义类型名

typedef 的使用
关键字typedef用来为已经存在的数据类型定义一个“别名”,使程序“更具有”可读性。
  例如:     typedef    unsigned int     uint;
                typedef   int *      ptrint;
         typedef    struct stu_info     StuInfo;
                则,ptrint   p1; 与  int *    p1; 等价。
   注意 ptrint   p1,p2;
   以及 #define   ptrint    int*
   ptrint   p1,p2; 的区别。

一般格式:

typedef     原数据类型     新类型名;

typedef     struct  stu_info     StuInfo;


2.用typedef定义类型名

typedef   struct   stu_info
{       
    char  name[12];      /*学生姓名*/
    int num;                   /*学生学号*/
    char id_card[19];   /*身份证号码*/                
    int m_score;          /*数学成绩*/
    int c_score;           /*语文成绩*/
    int h_score;          /*历史成绩*/
} StuInfo;

其中, StuInfo是新类型名



1 0