ProgrammingHardIBM · Deloitte pattern

Assume 32-bit int. What is printed?

Assume 32-bit int. What is printed?
int a = 6, b = 3;
printf("%d %d %d %d", a & b, a | b, a ^ b, ~a);
  1. A. 2 7 5 -7
  2. B. 2 7 5 -6
  3. C. 3 7 5 -7
  4. D. 2 6 5 -7

Correct answer: A. 2 7 5 -7

6=0110, 3=0011. AND: 0010=2. OR: 0111=7. XOR: 0101=5. ~6 flips all bits of 0...0110, giving -7 in two's complement (since ~x = -x-1, so ~6 = -7).

More C Programming questions

Exams that ask this topic