方法一:
在定义结构体变量时进行初始化。
struct DAY {
int year;
int month;
int day;
};
struct DAY today = { 2023, 2, 15};
方法二:
使用数据类型强制转换。
struct DAY {
int year;
int month;
int day;
};
struct DAY today;
today = (struct DAY){ 2022, 5 ,19};
当然也可以使用指针。
struct DAY {
int year;
int month;
int day;
};
struct DAY today;
struct DAY *p = &today;
*p = (struct DAY){ 2022, 5 ,19};