& And && differences and connections, | and || differences and connections

& And && differences and connections, | and || differences and connections, the actual project, in what circumstances?

First of all, & and && contact (common):

& && and can be used as a logical AND operator, but depends on the specific conditions of use is determined.

 

Case 1: when said operand is a boolean variable, & && and can be used as the logical AND operator.

Case 2: When the above expression is a boolean variable, & && and can be used as the logical AND operator.

Represents a logical AND (and), or when the result operand expressions both sides of the operator are true, the result of the operation before the whole is true, otherwise, as long as one of them is false, the results are false.

& & & And the difference (difference):

1) & Logical operators are called logical AND operator, && logical operators AND operator is called short-circuit, also called a logical AND operator.

2) &: whatever the case, both sides of the & operand or expression are involved in the calculation.

3) &&: when the left operand && expression is false result is false or the left, the right operand && expression will not participate in or calculated, then the end result is false.

In summary, if the first operand is a logical AND operator a false result or the expression is false, the second operand, or whether the calculation expression, it had no effect on the final result, the result is definitely false. && recommended multi-purpose, because some of its higher efficiency.

Attachment: & bitwise operators may also be used. When the result of the expression or the number of sides of the operation & both sides is not a boolean, an operation & bitwise operator.

| And differences and connections with the difference between & and && and || contact similar.

Guess you like

Origin www.cnblogs.com/sinoaccer/p/12001922.html