[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;
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM