问题在布尔表达式与if语句 [英] problem in boolean expression with if statement

查看:172
本文介绍了问题在布尔表达式与if语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些确认。我总是得到正确的o / p,但有人告诉我以下表达式将无法正常工作

I need some confirmation. I always get correct o/p but someone told me following expression will not work

提前感谢。

#define a 11

#define b 12

#define c 13     
    // I want if array[i] has values of any of these  then do something
    if( array[i] ==  (a) ||(b) ||( c))    
   // some function    
  else    
  printf("no match"); 


推荐答案

使用以下代码替换代码:

Replace your code with this:

if(array [i] == a || array [i] == b || array [i] == c)

布尔条件的每一部分必须是一个完整的表达式。虽然你写的是有效的C代码,但它并没有达到你想要的目的:你需要在每个部分进行数组元素比较。

Each part of the boolean condition must be a complete expression. While what you wrote is valid C code, it doesn't achieve what you want: you need to make an array element comparison in every part.

这篇关于问题在布尔表达式与if语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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