警告:建议用作真值赋值左右括号[-Wparentheses] [英] warning: suggest parentheses around assignment used as truth value [-Wparentheses]

查看:2173
本文介绍了警告:建议用作真值赋值左右括号[-Wparentheses]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  1. 节目片段是为素数提取写的。

  2. 该警告是由编译器作为之类的标题抛出。

  1. The program snippet was written for prime number extraction.
  2. The warning was thrown by the compiler as that like the title.

while(count<=n)
{ 
  for(c=2;c=(i-1);c++) //the warning is shown here
  { 
     if(i%c==0) 
       break; 
  }     
  if(c==i) 
  { 
     printf("%d ",i); 
     count++; 
  } 
  i++; 
}


感谢你提前!

推荐答案

如果语句的中间前pression通常是有条件的,如 I&LT; ñ。你的情况,这是一个任务。

The middle expression of an if statement is usually a conditional such as i < n. In your case, it is an assignment.

编译器警告你,或许你犯了一个错误,你想用

The compiler is warning you that perhaps you made a mistake and you meant to use

c == (i-1)

而不是

c = (i-1)

这篇关于警告:建议用作真值赋值左右括号[-Wparentheses]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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