其他分享
首页 > 其他分享> > [C]struct的定义的嵌套

[C]struct的定义的嵌套

作者:互联网

 

 

 

#include <stdio.h>

struct Person
{
    char name[10];
    char characteristic[20];
    struct Birthday { //嵌套了一个struct
        char month[10];
        int day;
        int year;
    } birthday;
    int age;
};

int main()
{
    struct Person man1 = {"jerry", "fastidious", {"June", 4, 1965}, 34}; //注意这里的对应顺序,可以用curly brace把Birthday括起来
    printf("My name is %s, I was born on %s-%d-%d, so I'm %d years old. My friends always complain I'm so %s\n.", \
        man1.name, man1.birthday.month, man1.birthday.day, man1.birthday.year, man1.age, man1.characteristic);
    return 0;
}

 

标签:man1,struct,int,name,char,嵌套,birthday,定义
来源: https://www.cnblogs.com/profesor/p/13045089.html