ProgrammingVery hard
In C99, what are the values of -8 % 3 and 8 % -3?
- A. 1 and -1
- B. -3 and -2
- C. -2 and 2
- D. 3 and 1
Correct answer: C. -2 and 2
The sign of % follows the dividend, so -8 % 3 = -2 and 8 % -3 = 2. Floor-based languages would give 1 and -1.
More C Programming questions
- What is 2^62 mod 1000000007?
- What is the total number of 1 bits in the binary representations of the integers 1 through 10?
- What is 1 ^ 2 ^ 3 ^ 4 ^ 5 ^ 6 ^ 7 ^ 8 ^ 9 ^ 10 in C?
- What is the Hamming distance between 13 and 22 (the number of bit positions where they differ)?
- unsigned int a = 3, b = 5; printf("%u", a - b + 3); What is printed on a 32-bit platform?
- printf("%d", -1 < 1u); What is printed?