Yes; this is guaranteed by the language:
[C++11: 5.6/4]:
The binary/
operator yields the quotient, and the binary%
operator yields the remainder from the division of the first expression by the second. If the second operand of/
or%
is zero the behavior is undefined. For integral operands the/
operator yields the algebraic quotient with any fractional part discarded; if the quotienta/b
is representable in the type of the result,(a/b)*b + a%b
is equal toa
.
In 3/2
, both 3
and 2
are integral operands; the algebraic quotient of this operation is 1.5
, and when you discard the fractional part .5
, you get 1
. This holds for your other examples and, well, all other examples.