Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C

Division assignment (/=)

The /= operator divides the left operand's existing value by the right operand and stores the result back.

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

Syntax

lhs /= rhs

lhs /= rhs corresponds to lhs = lhs / (rhs), but evaluates the left operand only once. It requires a modifiable arithmetic lvalue and operands permitted for /; pointers are unsupported.

Division follows the usual arithmetic conversions. With integer operands, the quotient is truncated toward zero. The result is then converted to the left operand's type: an int divided by a double does not retain a fractional part after storage.

Avoid a zero divisor; the core C rules make such division undefined behavior. Integer division is also undefined when its quotient cannot fit the result type, for example INT_MIN / -1.

Examples

#include <stdio.h>

int main(void)
{
    int whole = -17;
    double fraction = 17.0;
    int narrowed = 17;

    whole /= 4;
    fraction /= 4;
    narrowed /= 2.0;

    printf("%d %.2f %d\n", whole, fraction, narrowed);
    return 0;
}

Result

-4 4.25 8

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