[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