CKTIS / C
Division operator /
The / operator divides two operands. Integer division discards the fractional part; conversion before division enables a floating-point result.
Version: C23; repository compiler flag, production runtime not attested
Syntax
a / ba / b requires arithmetic operands. The usual arithmetic conversions determine a common type; mixing signed and unsigned types can change a value.
For integers, the result truncates toward zero: 7 / 2 yields 3, and -7 / 2 yields -3. (double)a / b performs floating-point division; (double)(a / b) converts the already-truncated result. Floating-point results may be rounded.
A zero divisor generally means undefined behavior; Annex F specifies floating-point exceptions. An unrepresentable integer quotient also means undefined behavior.
/ has higher precedence than binary + and -. Unary + and - have higher precedence than /, so -a / b groups as (-a) / b. Successive divisions group from the left.
Examples
#include <stdio.h>
int main(void)
{
int a = 7;
int b = 2;
printf("%d\n", a / b);
printf("%d\n", -a / b);
printf("%.1f\n", (double)a / b);
printf("%.1f\n", (double)(a / b));
return 0;
}Result
3 -3 3.5 3.0
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.