Search code examples
cbit-manipulationcompound-operator

C - Logical Compound Operators


Is the compound operator '&=' logical or bitwise AND ?

In other words, is a &= b the same as:

  • a = a & b
  • a = a && b

Solution

  • a &= b is using the bitwise AND operator. Think of the += operation:

    a += 5;
    

    is the same as:

    a = a + 5;
    

    It's just a combination of two operations: & and =.