ProgrammingHard
In C99 and later, what are the values of (-7) / 2 and (-7) % 2?
- A. -4 and 1
- B. -3 and -1
- C. -3 and 2
- D. -2 and -1
Correct answer: B. -3 and -1
Division truncates toward zero, so -7 / 2 = -3, and the remainder keeps the sign of the dividend, -7 - (-3)(2) = -1.
More C Programming questions
- The modular inverse of 3 modulo 1000000007 is which value?
- Which expression is correct for (a b) % MOD with MOD = 1000000007 and 0 <= a, b < MOD, to avoid overflow in C?
- How many times does the loop x &= x - 1 run for x = 0b101100 before x becomes 0?
- For unsigned x = 40 (binary 101000), what is x & -x?
- Reversing the 8 bits of 0b00010110 gives which value in decimal?
- The Gray code of 5 (binary 101), computed as n ^ (n >> 1), is which value?