A, c in the structure is defined by:
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 define a pointer type structure
//单链表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
Such defined structures can not be nested, i.e., can not contain its own internal
Two, c ++
All of the above applies to c ++, but more convenient in c ++ in:
struct Stu{
char name[10];
int age;
//...
};
Stu student_a; //OK, 定义了一个Stu类型的结构体变量student_a
Unfinished ...