Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C

Remainder operator (%)

The % operator computes the remainder of integer division. Results can be negative; a zero divisor causes undefined behavior.

Version: C23; repository compiler flag, production runtime not attested

Syntax

a % b

a % b requires integer operands, not floating-point operands. Usual arithmetic conversions determine the common operand and result type; mixing signed and unsigned types requires care.

Integer division truncates toward zero. When the quotient is representable, (a / b) * b + a % b == a. A nonzero remainder has the converted dividend's sign: -17 % 5 yields -2, not positive modulo.

A zero divisor or unrepresentable quotient causes undefined behavior. This includes INT_MIN % -1 with int operands, despite the mathematical remainder being zero.

Examples

#include <stdio.h>

int main(void)
{
    printf("%d %d %d\n", 17 % 5, -17 % 5, 17 % -5);
    return 0;
}

Result

2 -2 2

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources