Question 10
Back to Exercise
What is the output of the following C program?
#include <stdio.h>
int main(void) {
int a = -7;
printf("%d %d %d\n", -a % 3, a / -2, -(a % 4));
return 0;
}
- A 1 3 3 Correct
- B -1 3 3
- C 1 -3 3
- D 1 3 -3
Correct Answer: Option A
Unary minus binds tighter than %: (-a) % 3 = 7 % 3 = 1. −7 / −2 = 3.5 → 3 (toward zero). −7 % 4 = −3, negated: 3.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!