C 中的结构,编译器错误 [英] Structs in C, compiler error
本文介绍了C 中的结构,编译器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收到此错误:
str.c:5:19: error: expected identifier or '(' before 'struct'
编译以下代码时.有什么问题吗?
when compiling the following code. What is wrong with it?
#include <stdio.h>
struct addpoints (struct point p1, struct point p2){
p1.x += p2.x;
p1.y += p2.y;
return p1;
}
int main(){
struct point{
int x;
int y;
};
struct point p1 = { 13, 22 };
struct point p2 = { 10, 10 };
addpoints (p1,p2);
printf("%d\n", p1.x);
}
推荐答案
struct addpoints (struct point p1, struct point p2){
struct
不是类型.struct point
是一种类型.
struct
is not a type. struct point
is a type.
在使用之前声明你的struct point
类型,这里你在main
函数中声明struct point
.
Also declare your struct point
type before using it, here you are declaring struct point
in main
function.
这篇关于C 中的结构,编译器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文