错误:预期在'&'之前的';',','或')'令牌|在网上找到的简单C程序上 [英] error: expected ';', ',' or ')' before '&' token| on a simple C program found online
问题描述
我在网上找到了该程序来练习C。当我尝试在代码块中编译该程序时,在&标记|之前遇到了错误错误:预期';',','或')'。 (代码中提到)。如果有人可以向我解释错误的原因,那将非常有帮助。
I found this program online to practice C. When I tried to compile this program in Code blocks, I am getting this error "error: expected ';', ',' or ')' before '&' token| " in two places (mentioned in the codes). It would be really helpful, if someone could explain me the reason for the error.
#include<stdio.h>
int f1(int x,int y)
{
x=x+2;
y=y+3;
return x+y;}
int f2(int &x,int y) //error: expected ';', ',' or ')' before '&' token|
{
x=x+2;
y=y+3;
return x+y;
}
int f3(int *x,int *y)
{
*x = *x+2;
*y = *y+3;
return *x+*y;
}
int f4(int x,int &y,int *z)//error: expected ';', ',' or ')' before '&' token|
{ x=x+y;
y=*z+3;
z=&x;
*z=y*2;
return *z;
}
main()
{
int k=3,m=5,r=0;
printf("1) %d %d %d\n",k,m,r);
r=f1(k,m);
printf("2) %d %d %d\n",k,m,r);
r=f2(k,m);
printf("1) %d %d %d\n",k,m,r);
r=f3(&k,&m);
printf("1) %d %d %d\n",k,m,r);
r=f4(k,m,&r);
printf("1) %d %d %d\n",k,m,r);
return 0;
}
推荐答案
这不是C程序。这是一个C ++程序。它并没有使用太多的C ++功能,但是它使用了足够多的代码使该代码无法作为C代码进行编译。
This is not a C program. This is a C++ program. It does not use too many C++ features, but it uses enough to make this code non-compilable as C code.
要么将其编译为C ++,要么将其转换为C。后者将需要重写该代码的很多行。
Either compile it as C++ or convert it to C. The latter would require rewriting quite a few lines of that code.
这篇关于错误:预期在'&'之前的';',','或')'令牌|在网上找到的简单C程序上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!