Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt

Use this file to discover all available pages before exploring further.

The |= operator is the bitwise inclusive OR assignment operator in C. It performs a bitwise OR operation between the binary representations of the left and right operands, and subsequently assigns the computed result to the left operand.

Syntax and Equivalence

lvalue |= rvalue;
This compound assignment is semantically equivalent to the following expanded form, with the critical distinction that the lvalue is evaluated exactly once:
lvalue = lvalue | (rvalue);
The single evaluation is significant when the left operand contains side effects, such as a post-increment operation (e.g., *ptr++ |= 0x0F;).

Mechanics

The operator evaluates the operands bit by bit. For each corresponding bit position:
  • If either or both bits are 1, the resulting bit is 1.
  • If both bits are 0, the resulting bit is 0.
#include <stdint.h>

int main(void) {
    uint8_t a = 10;  // Binary: 0000 1010
    uint8_t b = 6;   // Binary: 0000 0110

    a |= b;          // 'a' becomes 14
                     // Binary result: 0000 1110
                     
    return 0;
}

Type Constraints

  • Integral Types Only: Both operands must be of integral types (e.g., char, short, int, long, unsigned variants, or _Bool).
  • Floating-Point Prohibition: Attempting to use |= with floating-point types (float, double) violates C language constraints and will trigger a compilation error.
  • Integer Promotions: Before the bitwise operation occurs, standard integer promotions are applied to the operands. If the operands have different types, standard arithmetic conversions are performed to bring them to a common type before the OR operation and subsequent assignment.
Master C with Deep Grasping Methodology!Learn More