如下列代码——先定义一个结构类型type1,再定义一个结构类型type2,而type2中含有type1这种结构类型。
#include <stdio.h>
struct type1 {//结构类型type1
int x;
int y;
};
struct type2 {//结构类型type2
struct type1 p;
int z;
};
void fuck(struct type2 *A_input);
void main() {
struct type2 A;//结构变量A,类型为type2
A.p.x = 1;
A.p.y = 2;
A.z = 3;
fuck(&A);
printf("A.p.x=%i\nA.p.y=%i\nA.z=%i", A.p.x, A.p.y, A.z);
}
void fuck(struct type2 *A_input) {//输入参数——结构变量地址
(*A_input).p.x = 5;
(*A_input).p.y = 6;
(*A_input).z = 7;
}
如下图,结构以及嵌套结构的基本构造。
比如,定义了一个类型为type2的结构变量A后,A就拥有了:A.p.x、A.p.y以及A.z这3个子值。