- Now that you have learnt about bitwise operators, you must have realized
&is very different from&&. Similarily|is very different from|| -
&or|work on integers performing the operator on each corresponding bits. However,&&or||work on boolean values ( Any non zero value is true ) to produce a boolean result.
Example :
2 | 1 = 3
2 || 1 = true
2 & 1 = 0
2 && 1 = true
- Very similar to the fact that
you can rewriteA = A + BasA += B,
you can rewrite
A = A | BasA |= Bor
A = A & BasA &= B