ProgrammingVery hard
In C, what is the result of 7 / -2 and 7 % -2?
- A. -4 and -1
- B. -2 and 3
- C. -3 and 1
- D. 4 and 3
Correct answer: C. -3 and 1
Division truncates toward zero, so 7 / -2 = -3. The remainder takes the sign of the dividend, so 7 - (-3)(-2) = 1.
More C Programming questions
- An unsigned short variable holds 65535 and is then incremented once with x++. What value does it hold?
- Which statement about left-shifting a negative signed integer in C is correct?
- How many subsets of {1, 2, 3, 4} (including the empty set) have XOR equal to 0?
- What is the result of (0xFFu >> 4) | (0x0Fu << 4) & 0xFF?
- How many times does cnt++ run in: for (i = 0; i < 10; i++) for (j = i; j < 10; j++) cnt++; ?
- How many iterations does for (i = 1; i < 1024; i = 2) do?