Question 6
Back to Exercise
What is the output of the following C program?
#include <stdio.h>
int main(void) {
int a = 4, b = 0, c = 2;
printf("%d %d %d\n", !a != !b, !a != !c, a ^ c);
return 0;
}
- A 1 0 6 Correct
- B 1 1 6
- C 0 0 0
- D 1 0 0
Correct Answer: Option A
a is true and b false: exactly one, so 1. a and c are both true: 0. But bitwise 4 ^ 2 is 6 (true!), even though both flags are set – which is why ^ is not a logical XOR.
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!