什么之间的差(&放大器;&放大器;和&安培)和(||和|)? [英] What's the difference between (&& and &) and (|| and |)?

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

问题描述

可能重复:结果
  逻辑VS按位

标题可能是本身的一个条件:)
反正,怎么办逻辑和位运营商各不相同?例如,在if语句,如如果(真||假),怎么会从不同,如果(TRUE | FALSE)?同去与如果(真放;&安培;假)如果(真放;假)
MUY格拉西亚斯,新手

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

推荐答案

的逻辑运算符&放大器;&安培; || 总是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.

位运算符&放大器; | 每个位分别操作

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

例如:

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

如果你仅仅使用布尔变量则两套运营商应该具有相同的行为除了逻辑运算符的短路特性。

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.

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

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