Differences between C ++ operators & | and |

Source: Internet
Author: User

& Is a logical operator, & Is a bitwise Operator

& | You can perform logical operations or bit operations,

&, | The two sides can only be bool type
&, | The two sides can be bool type or numeric type

Differences:
If (A & B) if A is false, the entire expression is false and the value of B is no longer calculated.
If (A & B) if A is false, the entire expression is false, but the value of B must be calculated.

If (A & B ++)If a is false
If (A & B ++) if A is false, & the following value is calculated.

(&) Pre-defines two operation rules for integer and bool types.For integer, & Calculates the bitwise "and" of the operands ";Bool operations, & Calculates the logic of the operand "and ";

That is to say, the bool type and the IF judgment result of & are the same.

For Integer Data & only true and false (0 or not), data on both sidesAll must be trueOrEither party is false;

Perform bitwise AND operation on the integer data and the data on both sides, and return the calculation result so that if can judge the value.

Logic (and): True & false: false
By-bit (and): 1001 0110 & 1111 1111: 1001 0110 (Binary)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.