gpt4 book ai didi

c - 为什么编译器在使用结构变量时显示 "Type specifier missing"

转载 作者:行者123 更新时间:2023-11-30 18:20:45 25 4
gpt4 key购买 nike

我正在学习 C 语言并尝试了解一些有关结构的知识,我在下面有这个示例,我试图了解结构内存分配是如何组成的。我了解到结构中的每个字段都是字大小的,因此如果没有使用足够的内存,则会出现示例中应该看到的空内存空间,但是编译器给了我几个错误,例如 类型说明符丢失预期 '类型名称需要说明符或限定符。怎么会?

#include <stddef.h>
#include <stdio.h>

typedef struct
{
char name[25];
int id;
int year;
char material;
} Student;

int
main(void)
{
Student talu;
printf("Size of tAlu %d\n", (int)sizeof(talu));
printf("name size is %d\n", offsetof(talu, name));
printf("id size is %d\n", offsetof(talu, id));
printf("year size is %d\n", offsetof(talu, year));
printf("material size is %d\n", offsetof(talu, material));
return 0;
}

最佳答案

这是因为你忘记了右括号:

char name[25];
// ^^^ !

关于c - 为什么编译器在使用结构变量时显示 "Type specifier missing",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13535071/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com