In this C++ tutorial, you shall learn about Bitwise OR Assignment operator, its syntax, and how to use this operator, with examples.

C++ Bitwise OR Assignment

In C++, Bitwise OR Assignment Operator is used to compute the Bitwise OR operation of left and right operands, and assign the result back to left operand.

The syntax to compute bitwise OR a value of 2 and value in variable x, and assign the result back to x using Bitwise OR Assignment Operator is

x |= 2


In the following example, we take a variable x with an initial value of 9, add bitwise OR it with value of 2, and assign the result to x, using Bitwise OR Assignment Operator.


#include <iostream>
using namespace std;

int main() {
    int x = 9;
    x |= 2;
    cout << "x : " << x << endl;


x : 11
Program ended with exit code: 0


In this C++ Tutorial, we learned about Bitwise OR Assignment Operator in C++, with examples.