What does the |= operator mean in C++?

后端 未结 4 784
無奈伤痛
無奈伤痛 2020-12-06 01:25

What does the |= operator mean in C++?

4条回答
  •  Happy的楠姐
    2020-12-06 02:07

    It is a bitwise OR compound assignment.

    In the same way as you can write x += y to mean x = x + y

    you can write x |= y to mean x = x | y, which ORs together all the bits of x and y and then places the result in x.

    Beware that it can be overloaded, but for basic types you should be ok :-)

提交回复
热议问题