c/c++结构体总结
一、c中结构体定义方式:
1
struct Stu{
    char name[10];
    int age;
    //...
};
struct Stu student;2
typedef struct Stu{
    char name[10];
    int age;
    //...
}St; //此处的S为结构体变量名Stu的别名
struct St student;
St student;3
struct Stu{
    char name[10];
    int age;
    //...
}stu_a, stu_b; //stu_a, stu_b都是Stu结构体类型的变量
//此外亦可再定义:
struct Stu stu_c;4 定义指针型结构体
//单链表1
struct LNode{
    int val;
    LNode *next;
    //...
};
typedef LNode *LinkList ;
//单链表2
typedef struct LNode{
    int val;
    LNode *next;
    //...
}LNode, *LinkList;5
struct{
    char name[10];
    int age;
    //...
}stu_a, stu_b; //stu_a,stu_b都是匿名结构体变量,即:
stu_a.name="stuname"; //OK
stu_b.age=18;         //OK
//但无法在其它地方定义这样的结构体变量,因为该结构体为匿名结构体,无法得知其标识符6
typedef struct{
    char name[10];
    int age;
    //...
}Stu_a, Stu_b;
//此处的stu_a,stu_b皆为该结构体的别名,而非变量明
//即:
Stu_a student1; Stu_b student2; //OK这样定义的结构体无法嵌套,即内部无法包含自身
二、c++
以上都适用于c++,不过在c++中更加方便:
struct Stu{
    char name[10];
    int age;
    //...
};
Stu student_a; //OK, 定义了一个Stu类型的结构体变量student_a未完...
相关推荐
  专注前端开发    2020-08-16  
   ericasadun    2020-06-03  
   cmsmdn    2020-04-19  
   twater000    2020-04-14  
   GoatSucker    2020-04-11  
   xuguiyi00    2020-04-11  
   GoatSucker    2020-04-10  
   shenwenjie    2020-03-03  
   lynjay    2020-02-28  
   cmsmdn    2020-02-22  
   sunnyJam    2020-02-18  
   linmufeng    2020-02-18  
   tydldd    2020-02-16  
   sunnyJam    2020-02-14  
   KilluaZoldyck    2019-12-28  
   lynjay    2019-12-31  
   徐建岗网络管理    2019-12-24  
   cherayliu    2019-12-15  
 