错误:表达式语法,警告:R被分配一个从未使用过的值。,plz help [英] Error: expression syntax, warning: R is assigned a value that is never used., plz help

查看:203
本文介绍了错误:表达式语法,警告:R被分配一个从未使用过的值。,plz help的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  #include   <   stdio.h  >  
#include < conio.h >
#include < math.h >
void main()
{
int p = 20 ,q = 15 ,r,s;
clrscr();
r = ++ p - q;
s = q +++ p;
printf( p =%dq =%ds =%d \ n, p,q,s);
printf( p * = q =%d \ n,p * = q);
printf( %d \ n,(r> s)?!: 0 );
}





我的尝试:



plz帮我解决这个问题,我是新手,我还没有尝试过任何东西,尽快回复

解决方案

错误和警告信息包含行号,通常还包含指示错误发生位置的列号。看看指示的线并检查它们。



此行可能出现错误:

 s = q +++ p; 

C / C ++没有 +++ 运算符。编译器不知道你的意思是

 s = q + ++ p; 



 s = q ++ + p; 



警告只是为了通知您代码中可能存在逻辑错误,因为您已将值赋给 r 但之后从未使用过它。代码将编译并运行,但您可能无法获得预期的结果。





你可以看到它是一个很好的想提一下行号(或者更好地在发布的代码中表明它)。所以我错过了真正的错误

 printf(%d \ n,(r> s)?!:0); 

参见还有其他解决方案。

警告是由于该错误造成的:由于错误,编译器未评估(r> s)处理 r 因此未使用。



我还必须更正上述关于的陈述+++ 。编译器应将其处理为

 s = q ++ + p; 

因为 ++ 运算符的优先级高于add运算符。

[/ EDIT]


引用:

s = q +++ p;

在这里你必须做出决定,

 s = q + ++ p; 



 s = q ++ + p; 







Quote:

printf(%d \ n,(r> s)?! :0);

这是另一种语法错误。你的意思是

 printf(%d \ n,(r> s)?1:0); 


看第12行:

 printf( %d \ n,(r> s)?!: 0 ); 



!它不是一个价值,而是一个运营商。我认为你的意思是:

 printf( %d \ n,(r> s)?1: 0 ); 


#include<stdio.h>
#include<conio.h>
#include<math.h>
void main( )
{
int p = 20, q = 15, r,s;
clrscr( );
r = ++p – q;
s = q+++p;
printf("p = %d q = %d s = %d \n", p, q, s);
printf("p*=q=%d\n",p*=q);
printf("%d \n", (r>s)?!:0);
}



What I have tried:

plz help me solve this issue, i am novice here, i havent tried anything yet, reply as soon as possible

解决方案

Error and warning messages contain a line number and often also a column number indicating where the error occurred. Have a look at the indicated lines and inspect them.

The error occured probably in this line:

s = q+++p;

C/C++ does not have a +++ operator. The compiler did not know if you mean

s = q + ++p;

or

s = q++ + p;


The warning is just to inform you that you might have a logical error in your code because you have assigned a value to r but never used it afterwards. The code will compile and run but you may no get the expected result.

[EDIT]
As you can see it is a good idea to mention the line number (or better indicate it in the posted code). So I missed the real error at

printf("%d \n", (r>s)?!:0);

See also the other solutions.
The warning is a result of that error: The compiler did not evaluate (r>s) due to the error and treated r therefore as unused.

I must also correct my above statement about the +++. The compiler should process it as

s = q++ + p;

because the ++ operator has a higher precedence than the add operator.
[/EDIT]


Quote:

s = q+++p;

Here you have to take a decision, either

s = q + ++p;

or

s = q++ + p;




Quote:

printf("%d \n", (r>s)?!:0);

That's another syntax error. Did you mean

printf("%d \n", ( r > s ) ? 1 : 0);

?


Look at line 12:

printf("%d \n", (r>s)?!:0);


"!" is not a value, it's an operator. I Think you meant:

printf("%d \n", (r>s)?1:0);


这篇关于错误:表达式语法,警告:R被分配一个从未使用过的值。,plz help的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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