Bitwise operators work on bits, logical operators evaluate boolean expressions. As long as expressions return bool
, why don\'t we use bitwise operators instead
You shouldn't. Assume you receive two values which allow you to proceed only if they are both non-zero.
int b = foo(1); // returns 0x1
int c = foo(2); // returns 0x2
Than the following conditions result in the follows: b && c == true
, while b & c == 0
if (b && c)
{
// This block will be entered
}
if (b & c)
{
// This block won't
}