c - 错误 : expected ';' , ',' 或 ')' token 之前的 '&'|在网上找到的一个简单的 C 程序

标签 c codeblocks

<分区>

我在网上找到这个程序来练习 C。当我试图在代码块中编译这个程序时,我得到这个错误“错误:在‘&’标记|之前预期‘;’、‘、’或‘)’”在两个地方(代码中提到)。如果有人能向我解释错误的原因,那将非常有帮助。

#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;
}

最佳答案

第 11 行应该是 int f2(int *x,int y)

您发布的代码是 C++ 代码。不是C代码。您不能在 C 编译器上执行 C++ 代码。

关于c - 错误 : expected ';' , ',' 或 ')' token 之前的 '&'|在网上找到的一个简单的 C 程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19782983/

相关文章:

c++ - 带有 VS 调试器的代码块 (IDE)

c++ - gotoXY 显示在屏幕上

c++ - 创建原始套接字 - Debian + Codeblocks

c - 我的第一杯Ragel

c++ - gtksourceview 在代码块中编译

c - 从结构返回值

c - 了解 strdup 函数

c++ - 代码块 : [highlight: No such directory found

c - 遍历数组并删除打印数组的第 i 个字符

c - 如何将字符串类型转换为具有不同大小的 char 数组成员的结构?