what is the difference between & and && operator?
[Doubt]Difference between operator
Hi @Amit1506,
The “&” and “&&” both are the operators, used to evaluate the conditional statements. The & operator is a logical as well as, a bitwise operator. The && operator is purely a Logical operator. The basic difference between the & and && operator is that the & operator evaluate both sides of the expression whereas, the && operator evaluates only the left-hand side of the expression to obtain the final result.
For example -> if(5>3 && 2<3) … in this case it only checks the left-hand side of the expression. If the left-hand side of the expression results in false, then it does not bother about evaluating the right-hand side of the expression.But in this case the answer is true for the left hand side expression hence it will evaluate the right hand expression .
The & operation -> It is more of a bitwise operation . for example 5&3 = 1 . This result is obtained by converting the values into their binary form . 5= 101 and 3=011 . and then the &(AND) operation is applied bitwise. That will result in the answer 001 which is 1 in decimal representation.