Amazon Interview Question
Software Engineer / DevelopersCountry: United States
a bit-wise operator considers each bit in the operand and a logical operator considers operand as a single.
if you perform logical OR on 3 and 4 the result will be 1 that is true as said in earlier reply
the bit-wise OR will give you a different result
3(011) logically ORed with 4(100) will give you 7(111)
& is bitwise operator and && is logical operator.
In a&b the bitwise operator checks both the left hand side and right hand side bit by bit and compares.
The logical operator on the other hand operates on the boolean values of the variables.
In a && b, the logical operator first checks the left hand side i.e. a and if its true then only it checks b.
All logical operators evaluate to either true or false (or 1 and 0), whereas bit-wise operators can evaluate to any number
- trunks7j February 13, 2013