int result; result = 125/100;
result = 43/100;
Will result always be the floor of the division? What is the defined behavior?
Sometimes. The integer quotient of the two operands is the floor, unless the exact quotient is negative.
and the corresponding footnote:
Of course two points to note are:
Dirkgently gives an excellent description of integer division in C99, but you should also know that in C89 integer division with a negative operand has an implementation-defined direction.
From the ANSI C draft (3.3.5):
So watch out with negative numbers when you are stuck with a C89 compiler.
It's a fun fact that C99 chose truncation towards zero because that was how FORTRAN did it. See this message on comp.std.c.
Where the result is negative, C truncates towards 0 rather than flooring - I learnt this reading about why Python integer division always floors here: Why Python's Integer Division Floors
Yes, the result is always floor of the division for positive integers. It will round towards smallest absolute value.
No. The result varies, but variation happens only for negative values.
To make it clear floor rounds towards negative infinity,while integer division rounds towards zero (truncates)
For positive values they are the same
For negative value this is different