typedef struct

在C中定义一个结构体类型要用typedef:
    typedef struct Student
    {
    int a;
    }Stu;
    于是在声明变量的时候就可:Stu stu1;(如果没有typedef就必须用struct Student stu1;来声明)
    这里的Stu实际上就是struct Student的别名。Stu==struct Student
    另外这里也可以不写Student(于是也不能struct Student stu1;了,必须是Stu stu1;)
    typedef struct
    {
    int a;
    }Stu;
    但在c++里很简单,直接    //不需要typedef来定义类型  用typedef的(如上面写法)其实是c的坏习惯 不好
    struct Student
    {
    int a;
    };    
    于是就定义了结构体类型Student,声明变量时直接Student stu2;



typedef struct tagMyStruct

    { 
     int iNum;
     long lLength;
    } MyStruct;   

在C中,这个申明后申请结构变量的方法有两种:

    (1)struct tagMyStruct 变量名

    (2)MyStruct 变量名

    在c++中可以有

    (1)struct tagMyStruct 变量名

    (2)MyStruct 变量名

    (3)tagMyStruct 变量名



posted @ 2014-05-19 19:56  sssssnian  阅读(237)  评论(0)    收藏  举报