c modulus operator

后端 未结 5 532
独厮守ぢ
独厮守ぢ 2021-01-25 13:42

what happens when you use negative operators with %. example -3%2 or 3%-2

5条回答
  •  生来不讨喜
    2021-01-25 14:01

    In C89, C90, and C++03 the standards requires only that (a/b)*b+a%b == a for the / and % operators.

    If both operands are nonnegative then the remainder is nonnegative; if not, the sign of the remainder is implementation-defined

    Edit: In C99 a negative number will be returned if the first argument is negative

提交回复
热议问题