结构体
解释:在使用C语言的时候,往往基本数据类型不能满足我们的需要,所以结构体这个概念也应运而生。结构体能够组合几种不同的基本数据类或其它数据类型形成一个新的数据类型。类似于面对对象中的类。
- 声明
关键字:struct
形式:
struct node {
int one;
char two;
}; //;作为结构体的一部分 不能省去
- 定义
struct node {
int one;
char two;
}Node;
形式2:
struct {
int one;
char two;
}Node;
形式3:
struct node {
int one;
char two;
};
struct node Node;
- 初始化
struct node {
int one;
char two;
}Node; //默认初始化int型为0 char型为null
形式2:
struct node {
int one;
char two;
}Node={1, '2'};
形式3:
struct node {
int one;
char two;
};
struct node Node;
Node = {1, '2'};
- 结构体的引用
struct node {
int one;
char two;
}Node={1, '2'};
struct node temp;
temp = Node;
成员引用:
struct node {
int one;
char two;
}Node={1, '2'};
Node.one = 2;
ps:如有错误,请指正,谢谢!