The operator |
in C is known a s bitwise OR operator. Similar to other bitwise operators (say AND &
), bitwise OR only operates at the bit level. Its result is a 1
if one of the either bits is 1
and zero only when both bits are 0
. The |
which can be called a pipe! Look at the following:
bit a bit b a | b (a OR b)
0 0 0
0 1 1
1 0 1
1 1 1
In the expression, you mentioned:
var1 = x | y | z | ...;
as there are many |
in a single statement, you have to know that, bitwise OR operator has Left-to-right Associativity means the operations are grouped from the left. Hence the above expression would be interpreted as:
var1 = (x | y) | z | ...
=> var1 = ((x | y) | z) | ...
....
Read more about Associativity here.