k=25;
++k;
k++;
k|7&12;
After the first 3 lines, k
is 27. In the fourth expression, the bitwise AND operator &
has higher precedence than the bitwise OR operator |
, so it is equivalent to 27|(7&12);
Converting the values to binary gives us 11011|(00111&01100);
The inner part evaluates to 00100
, then 11011|00100
evaluates to 11111
, which is 31.
The value of this expression appears in a void
context (i.e. it isn’t assigned to anything) and gets discarded.
fp=10/20;
The constants 10
and 20
are both of type int
. So integer division is performed, which results in 0. That value is then cast to float
and assigned to fp
.
fp=(float)10/20;
The constant 10
is casted to float
, then divided by 20
. Since one of the operands is of type float
, the other is promoted to than type and floating point division is performed, resulting in 0.5
. That value is then assigned to fp
.
1
solved Evaluating C binary operations