本文介绍了(&&和&)和(||和|)之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标题本身可能是一个条件:)
无论如何,逻辑和按位运算符之间的区别如何?例如,在 if(true || false)的if语句中,与 if(true | false)?同样, if(true&& false) if(true& false)
新手

The title could be a condition in itself :)Anyway, how do the logical and bitwise and and or operators differ from each other? For example, in an if statement such as if(true || false), how would that differ from if(true | false)? Same goes with if(true && false) and if(true & false).Muy gracias, the newbie

推荐答案

逻辑运算符&& c $ c>和 || 总是evlauate为0或1,他们关心的是操作数是非零还是零。此外,这些运算符允许短路,这是非常有用的。

The logical operators && and || always evlauate to 0 or 1, and all they care about is whether the operands are non-zero or zero. Also, these operators allow short circuiting which is very useful.

位运算符& 和<$ c $

The bitwise operators & and | operate on each bit separately.

例如:

2 && 1 == 1
2 & 1  == 0
0 || 2 == 1
0 | 2  == 2

如果你只是使用bools,那么两组运算符的行为应该相同除了逻辑运算符的短路属性。

If you're just using bools then the two sets of operators should behave the same except for the short-circuiting property of the logical operators.

这篇关于(&amp;&amp;和&amp;)和(||和|)之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 18:46