我正在尝试弄清楚如何使用 struct,但这段代码给我带来了很多错误。
#include <stdio.h>
int main(void)
{
struct date
{
int today = 6;
int tomorrow = 7;
int threeDays = 8;
};
struct date date;
printf("%d", date.today);
return 0;
}
最佳答案
struct date
{
int today = 6;
int tomorrow = 7;
int threeDays = 8;
};
struct date date;
您不能为结构类型分配默认值。
您可以做的是用正确的值初始化一个结构类型的对象:
struct date
{
int today;
int tomorrow;
int threeDays;
};
struct date date = {6, 7, 8};
关于C - 新的结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19821241/