+ 1
Can someone answer it please: Compare “short circuit” logical operators (AND)&& and (OR) || with logical (AND)& and (OR) |
7 odpowiedzi
+ 3
short circuit logical operators are smarter than normal logical operator i.e. the short-circuit operator will evaluate the second expression only if needed
Let me explain you this with an example
Let say a=10 and b=20
Now consider the Boolean expression (a>b)AND(b>a) . We know that for AND operation the result is true iff both it's operand is true
In the above expression the result of (a>b) is false so the entire expression becomes false. In short circuit, the second operand is evaluated only if needed. As the result of the first operand is false there is no need to evaluate the second expression.
Where as in normal logical & both the operand is evaluated irrespective of the first operand result
+ 3
It's a operator overloading in Java
& is used both for bitwise and Boolean evaluation
+ 3
Yes
+ 3
The && and || are logical (boolean) operators, they are used to evaluate the operands as true/false.
The & and | are bitwise operators, they are used to process numbers (mostly integrals) by performing bitwise calculation on each bits.
There are differences in behaviour between these operators depending on the inputs (expressions, operands to evaluate). Have a look at the following link for more thorough explanation regarding the differences.
https://stackoverflow.com/questions/4014535/differences-in-boolean-operators-vs-and-vs
+ 1
ohk so does that mean that & work as bitwise as well as logical operator in java? Rishi Anand
0
ohk i do get your point. thank u. but i m also confused that & is considered a bitwise operator. what do you have to say about that? Rishi Anand
0
ohk thanks Rishi Anand