Bitwise inclusive OR operator |

The | (bitwise inclusive OR) operator compares the values (in binary format) of each operand and yields a value whose bit pattern shows which bits in either of the operands has the value 1. If both of the bits are 0, the result of that bit is 0; otherwise, the result is 1.

Both operands must have an integral or enumeration type. The usual arithmetic conversions on each operand are performed. The result has the same type as the converted operands and is not an lvalue.

Because the bitwise inclusive OR operator has both associative and commutative properties, the compiler can rearrange the operands in an expression that contains more than one bitwise inclusive OR operator. Note that the | character can be represented by the trigraph ??!.

The following example shows the values of a, b, and the result of a | b represented as 16-bit binary numbers:

bit pattern of a 0000000001011100
bit pattern of b 0000000000101110
bit pattern of a | b 0000000001111110
Note:
The bitwise OR (|) should not be confused with the logical OR (||) operator. For example,
   1 | 4 evaluates to 5
while
   1 || 4 evaluates to true

Related information



[ Top of Page | Previous Page | Next Page | Contents | Index ]