0

I was trying to find the answer to the following question, but was unsuccessful. I have the expression involving bit AND and bit OR (everything unsigned long):

A |= B & C

What is the order of evaluation in C++? Is it A = A | (B & C) or A = (A | B) & C? Or it depends on the compiler version? Thanks.

4
  • 3
  • 3
    You're "expanding" too soon. There are two possible interpretations when there are two binary operators - (A |= B) & C and A |= (B & C).
    – molbdnilo
    Feb 8, 2021 at 14:50
  • I'm curious to know, why couldn't you find the documentation for operator precedence? Do you just not know of the word "precedence"? Even searching for "order of evaluation", which appears in your question, turns up lots of good info for me.
    – Wyck
    Feb 8, 2021 at 14:50
  • 3
    Side note: "order of evaluation" and "precedence" are different things. It's easy to get lost if you confuse them.
    – molbdnilo
    Feb 8, 2021 at 15:00

1 Answer 1

2

With the compound assignment operators (op=), the expression E1 op= E2 becomes E1 = E1 op E21. That means for your code that E1 is A and E2 is B & C so the result would be

A = A | (B & C)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.