逻辑算符优先

来源:互联网 发布:三维机械建模软件 编辑:程序博客网 时间:2024/06/05 03:10

经营者can be used to关系测试特定条件是否是真实的虚假的,他们只能测试一个条件at a time我们常常需要知道是否true at盎司的条件For example,to checkwhether我们已经赢得彩票we have to all the numbers比较是否我们比赛all of the胜利彩票以及6个数,涉及6比较all of which have to be true其他的时代,我们需要知道是否any one of条件是真实的例如,我们可以决定跳过WorkToday,如果我们生病,如果我们累了或如果赢得彩票in our previousexample涉及检查是否any of 3比较是真实的

我们提供这一能力逻辑算子

C + +提供美国以及3逻辑算子one of which you have already seen

这个程序的图案“X等同去!”目的X does not equal所以如何这是可能的吗?theanswer is that has not because the逻辑算符优先Higher than the Equality算子表达X = Y实际上evaluates(x)= =自从X5X evaluates 00 = = y虚假的,所以the else statement executes

注意:任何整数evaluates to trueused in a Boolean上下文自从X5,Xevaluates to true,andX evaluates to false(0混合整数布尔操作,这样可以混淆,and should be是否避免了

the way to write the above正确的

1
2
3
4
5
6
7
intx = 5;
inty = 7;
 
if(! x == y)
    cout << "x does not equal y";
else
    cout << "x equals y";

0 0