C语言学习--结构体套结构体

#include<stdio.h>
#include<stdlib.h>


struct stu
{
    int id;
    int age;
    char name[128];
};

/*
struct heima_stu
{
    int id;
    int age;
    char names[128];
    int chinese;
    int match;

};*/

//可以这样定义上面那个结构体

struct heima_stu
{
    struct stu s; //定义一个stu的结构体变量
    int chinese;
    int math;

};



int main (void)
{


    //定义一个struct hei_mastu的结构体变量
    struct heima_stu heima;

    //init the struct
    heima.s.age = 10;
    heima.s.id = 11;
    strcpy(heima.s.name, "shun");
    heima.chinese = 111;
    heima.math = 222;

    printf("%d , %d , %s , %d ,%d", heima.s.age, heima.s.id, heima.s.name,heima.chinese, heima.math);


    return 0;

}

10 , 11 , shun , 111 ,222


 

 

posted @ 2022-10-29 22:19  朵朵奇fa  阅读(18)  评论(0编辑  收藏  举报