Skip to main content
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

This compound assignment is semantically equivalent to the following expanded form, with the critical distinction that the lvalue is evaluated exactly once:
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.

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.
Tired of Poor C Skills? Fix That With Deep Grasping!Learn More