What is the behavior of integer division?

Will result always be the floor of the division? What is the defined behavior? Not quite. It rounds toward 0, rather than flooring. 6.5.5 Multiplicative operators 6 When integers are divided, the result of the / operator is the algebraic quotient with any fractional part discarded.88) If the quotient a/b is representable, the expression (a/b)*b … Read more

Int division: Why is the result of 1/3 == 0?

The two operands (1 and 3) are integers, therefore integer arithmetic (division here) is used. Declaring the result variable as double just causes an implicit conversion to occur after division. Integer division of course returns the true result of division rounded towards zero. The result of 0.333… is thus rounded down to 0 here. (Note … Read more