What is the difference between the Boolean & operator and the && operator?
A single ampersand is used to perform ‘bit-wise AND’ operation on integer arguments. It constitutes the logical AND operator, which returns 1 if both bits in first and second arguments. Otherwise it returns 0. It always evaluates both the arguments.
A double ampersand is used to perform boolean operations, such as ‘logical AND’. It returns true if both the operands are true, otherwise returns false. It will evaluate the second argument if the first argument is true; otherwise the operation of the second operand is skipped.Example
A & B
In this, both the operands A as well as B are evaluated and then ‘&’ is applied to them.
A && B
In this, A is evaluated first. If A is true then B is evaluated and then the operand is applied to them.
If A is false, evaluation of B is skipped.