---
title: "3.15 Bitwise OR Operator (|)"
description: "The bitwise OR operator (`|`) performs a logical OR operation on each corresponding bit of two integral operands. A bit in the result is set to `1` if either corresponding operand bit is `1`. The result bit is `0` only…"
url: "https://edcret.in/docs/cpp-programming/operators-cplusplus/3-15-bitwise-or-operator/"
updated: "2026-07-28"
category: C++ Programming / Operators
---

# 3.15 Bitwise OR Operator (|)

The bitwise OR operator (`|`) performs a logical OR operation on each corresponding bit of two integral operands. A bit in the result is set to `1` if either corresponding operand bit is `1`. The result bit is `0` only when both corresponding bits are `0`.

Bitwise OR is commonly used to set one or more bits in a value without affecting other bits.

## Source Code

```
#include <iostream>

int main()
{
    int num1 = 12;
    int num2 = 10;

    int result = num1 | num2;

    std::cout << "First Number : " << num1 << '\n';
    std::cout << "Second Number: " << num2 << '\n';
    std::cout << "Result       : " << result << '\n';

    return 0;
}
```

## Output

```
First Number : 12
Second Number: 10
Result       : 14
```

## Explanation

- The bitwise OR operator (`|`) compares the corresponding bits of two integral operands.
- A result bit is set to `1` if either corresponding operand bit is `1`.
- A result bit is `0` only when both corresponding operand bits are `0`.
- The operands `12` and `10` have the following binary representations:`12 = 1100₂ 10 = 1010₂ -------------- | = 1110₂`
- The binary result `1110₂` is equal to the decimal value `14`.
- Bitwise OR operations are commonly used to set specific bits in flags and control registers.
- The bitwise OR operator is applicable only to integral data types.
- `return 0;` terminates the program successfully.
