Remainder operator %

The % (remainder) operator yields the remainder from the division of the left operand by the right operand. For example, the expression 5 % 3 yields 2. The result is not an lvalue.

Both operands must have an integral or enumeration type. If the right operand evaluates to 0, the result is undefined. If either operand has a negative value, the result is such that the following expression always yields the value of a if b is not 0 and a/b is representable:

   ( a / b ) * b + a %b;

The usual arithmetic conversions on the operands are performed.

C++ If both operands are negative, the sign of the remainder is also negative. Otherwise, the sign of the remainder is the same as the sign of the quotient.