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

 

上一篇:Dapper Oracle日期参数化


下一篇:原型模式