(解决)错误:预期',',','或')'前'和;'令牌|在网上找到了一个简单的C程序 [英] (Solved) error: expected ';', ',' or ')' before '&' token| on a simple C program found online

查看:293
本文介绍了(解决)错误:预期',',','或')'前'和;'令牌|在网上找到了一个简单的C程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

前'和','或')';预计'';:

我发现这个程序的在线练习C.当我试图编译这个程序在code块,我得到这个错误错误象征|在两个地方(在codeS自提)。这将是真正有用的,如果有人可以解释我的错误的原因。

 #包括LT&;&stdio.h中GT;
INT F1(INT X,int y)对
{X = X + 2;
Y = Y + 3;
返回X + Y;}
INT F2(INT和放大器; X,int y)对//错误:预期',',','或')'前'和;'令牌|{
 X = X + 2;
Y = Y + 3;
返回X + Y;
}
INT F3(INT * X,诠释* Y)
{* X = * X + 2;
* Y = * Y + 3;
返回* X + * Y;
}
INT F4(INT X,INT和放大器; Y,诠释* Z)//错误:预期';',','或之前')''和;'令牌|
{X = X + Y; Y = * Z + 3;
Z =&放大器; X;
* Z = Y * 2;
返回* Z;
}
主要()
{
INT K = 3时,m = 5,R = 0;
的printf(1)%D%d个\\ N,K,M,R);
R = F1(K,M);
的printf(2)%D%d个\\ N,K,M,R);
R = F2(K,M);
的printf(1)%D%d个\\ N,K,M,R);
R = F3(安培; K,和放大器; M);
的printf(1)%D%d个\\ N,K,M,R);
R = F4(K,M&安培; R);
的printf(1)%D%d个\\ N,K,M,R);返回0;
}


解决方案

这是不是一个C程序。这是一个C ++程序。它不使用太多的C ++的功能,但它使用足以让这个code非编译为C code。

无论其编译为C ++或将其转换为C.后者将需要重新编写code的不少线路。

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

解决方案

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.

Either compile it as C++ or convert it to C. The latter would require rewriting quite a few lines of that code.

这篇关于(解决)错误:预期',',','或')'前'和;'令牌|在网上找到了一个简单的C程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆