user2131316
user2131316

Reputation: 3287

what does "|=" operator mean 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?

Upvotes: 1

Views: 1465

Answers (7)

Antzi
Antzi

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

fableal
fableal

Reputation: 1617

Its the bitwise OR operator, and

a |= b;

Its the same thing as

a = a | b;

Upvotes: 2

Alex
Alex

Reputation: 10136

This is the same as

a = a | b;

The same way as += -= etc

Upvotes: 2

V-X
V-X

Reputation: 3029

This is compound assignment operator. It has meaning:

a = a | b;

Upvotes: 2

mah
mah

Reputation: 39837

The expression a |= b; is equivalent to the expression a = a | b;.

Upvotes: 2

Mr. Llama
Mr. Llama

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

cdhowie
cdhowie

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

Related Questions