How does this code work:
int a = 1;
int b = 10;
a |= b;
how the a |= b; works? Seems like |= is not an operator in C?
How does this code work:
int a = 1;
int b = 10;
a |= b;
how the a |= b; works? Seems like |= is not an operator in C?
It works like the | + the = operator, in a similar way as += works.
It is equivalent as
a = a|b;
I suggest you to read this article about operators: http://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B#Bitwise_operators Ans this one about bitwise operation http://en.wikipedia.org/wiki/Bitwise_operation
Following the pattern of, for example, +=:
a |= b;
// Means the same thing as:
a = a | b;
That is, any bits that are set in either a or b shall be set in a, and those set in neither shall not be set in a.
That's the "bitwise or" equal. It follows in the pattern of the plus equal +=, minus equal -=, etc.
a |= b; is the same as a = a | b;