结构体嵌套就是 在当前的结构体内的一个成员是另一个整体的结构体变量! 

struct Stu {
    char name[10];
    int age;
};
struct Teach {
    char TeachName[10];
    struct Stu st;
    int  TeachAge;

举个例子

#include <stdio.h>
#include <stdlib.h>
struct Stu {
    char name[10];
    int age;
};
struct Teach {
    char TeachName[10];
    struct Stu st;
    int  TeachAge;
};
int main(void)
{
    struct Teach te = { "张老师",{"小史",18},23 };//第二个成员是个结构体成员,也可以不写{}
    printf("%s,%d,%s,%d\n", te.TeachName, te.TeachAge, te.st.name,te.st.age);



    system("pause");
    return 0;
}

 

 posted on 2019-03-15 21:27  轻舞飞扬的饼  阅读(337)  评论(0编辑  收藏  举报