You cannot rely on this โworkingโ one (i.e. doing the same thing all the time, portable) in general, this behavior is undefined in C for the second case, and also for the first, if your implementation doesn't define __STDC_IEC_559__ (this, I find it rarely happens these days).
C99, ยง6.5.5 / 5
The result of the operator / is quotient of dividing the first operand by the second; the result of the% operator is the remainder. In both operations, if the value of the second operand is zero, the behavior is undefined.
The fact that you get "not a number" in one case, and not in the other, is that one is performed in floating point arithmetic, where on your implementation (in accordance with the division of IEEE 754 by zero semantics), 0/0 gives NaN.
In the second case, you use integer arithmetic - undefined, does not predict what will happen.
Mat
source share