& And &&, | the difference between ||

&和&&

In common:

& && and are represented: both ends of the symbol must be true at the same time, the final result will be true; wherein one end is false, then the final result is false

the difference:

&: The left is false, but also need to continue to determine the true and false at the right end

&&: left false, true and false judgments is not required right, i.e., no further operation right

| And ||

In common:

| And || have said: both ends of the symbols in one end is true, the final result is true; both ends are false, the final result is false

the difference:

|: Left whether true or false (even if true), but also the right to continue operations

||: true left and right ends no further operation, the result is true directly

to sum up

& And &&, | || run and the final result is the same

&& and || a little more efficient, to reduce unnecessary operations

Guess you like

Origin www.cnblogs.com/candy-xia/p/11577558.html