[C]struct结构变量在函数间传递

 

 

#include <stdio.h>

struct date
{
    int day;
    char month[10];
    int year;
};

void out(struct date); // 1.该行一定要置于struct date定义的下面, 2.struct date是新定义的一种数据结构,类比int, float

int main()
{
    struct date today;
    puts("input day: ");
    scanf("%d", &today.day);
    puts("input month: 'May', 'April': ");
    scanf("%9s", today.month);
    puts("input year: ");
    scanf("%d", &today.year);
    out(today);
    return 0;
}

void out(struct date t) // struct date是新定义的一种数据结构,类比int, float
{
    printf("%s-%d-%d\n", t.month, t.day, t.year);
}

 

posted @ 2020-06-04 17:20  profesor  阅读(288)  评论(0编辑  收藏  举报