简体   繁体   English

C中的“ | =”运算符是什么意思?

[英]what does “|=” operator mean in C?

How does this code work: 该代码如何工作:

int a = 1;
int b = 10;

a |= b;

how the a |= b; a |= b; works? 作品? Seems like |= is not an operator in C? 似乎|=不是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 我建议您阅读这篇有关运算符的文章: http : //en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B#Bitwise_operators这篇关于按位运算的文章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 . 也就是说,在ab中设置的任何位都应在a设置,而在这两个位置中均不设置的那些位不应在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; a = a | b;相同 a = a | b;

The expression a |= b; 表达式a |= b; is equivalent to the expression a = a | b; 等价于表达式a = a | b; a = a | b; .

This is compound assignment operator. 这是复合赋值运算符。 It has meaning: 它的含义是:

a = a | b;

This is the same as 这和

a = a | b;

The same way as += -= etc += -=等相同

Its the bitwise OR operator , and 它是按位OR运算符 ,以及

a |= b;

Its the same thing as 和...一样

a = a | b;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM