gpt4 book ai didi

结构错误之前的 C 预期表达式

转载 作者:行者123 更新时间:2023-11-30 21:43:44 25 4
gpt4 key购买 nike

为什么我在 struct at static void print_abc(struct abc); 之前收到预期表达式错误在主函数中?

struct abc{
int a;
int b;
int c;
};
static void print_abc(struct abc){
printf("&i &i &d",a,b,c);
}

int main(void){
static void print_abc(struct abc);
}

最佳答案

1

关键字static是一个关键字,在尝试调用带有static标记的函数时不需要添加。请参阅this了解更多信息。

2

您也不能将结构隐式转换为另一种数据类型。您正尝试在 print_abc 函数中执行此操作。您需要显式访问成员变量。

3

使用 printf 函数时,

&i 和 &d 不是插入整数的有效占位符。请改用 %d,请参阅 this了解更多信息。

代码应该是:

struct abc{
int a;
int b;
int c;
};
static void print_abc(struct abc){
printf("%d %d %d",abc.a,abc.b,abc.c);
}

int main(void){
void print_abc(struct abc);
}

关于结构错误之前的 C 预期表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33757975/

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