#include <stdio.h>
int main(int argc, char const *argv[])
{
// 声明结构类型
struct date
{
int month;
int day;
int year;
};
// 使用自定义的类型
struct date today;
today.month = 9;
today.day = 30;
today.year = 2019;
printf("Today is date is %i-%i-%i\n", today.year , today.month, today.day);
return 0;
}
二、在函数内/外 ?
和本地变量一样,在函数内部声明的结构类型只能在函数内部使用
所以通常在函数外部声明结果类型,这样就可以被多个函数使用了
#include <stdio.h>
struct date
{
int month;
int day;
int year;
};
int main(int argc, char const *argv[])
{
struct date today;
today.month = 9;
today.day = 30;
today.year = 2019;
printf("Today is date is %i-%i-%i\n", today.year , today.month, today.day);
return 0;
}