C++ “OR” operator

后端 未结 9 1596
无人及你
无人及你 2021-01-19 03:37

can this be done somehow?

if((a || b) == 0) return 1;
return 0;

so its like...if a OR b equals zero, then...but it is not working for me.

9条回答
  •  半阙折子戏
    2021-01-19 03:47

    You need to write the full expression:

    (a==0)||(b==0)
    

    And in the second code:

    if((p1.distanceFrom(l.p1)<= r) || (p1.distanceFrom(l.p2)<=r) )
        return 1;
    

    If you do ((a || b) == 0) this means "Is the logical or of a and b equal to 0. And that's not what you want here.

    And as a side note: the if (BooleanExpression)return true; else return false pattern can be shortened to return BooleanExpression;

提交回复
热议问题