C integer division and floor
问题 In C, is there a difference between integer division a/b and floor(a/b) where both a and b are integers? More specifically what happens during both processes? 回答1: a/b does integer division. If either a or b is negative, the result depends on the compiler (rounding can go toward zero or toward negative infinity in pre-C99; in C99+, the rounding goes toward 0). The result has type int . floor(a/b) does the same division, converts the result to double, discards the (nonexistent) fractional part