Reputation: 3287
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?
Upvotes: 1
Views: 1465
Reputation: 13444
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
Upvotes: 4
Reputation: 1617
Its the bitwise OR operator, and
a |= b;
Its the same thing as
a = a | b;
Upvotes: 2
Reputation: 20909
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;
Upvotes: 2
Reputation: 169353
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
.
Upvotes: 2