ProgrammingHardIBM · Deloitte pattern

Assume 32-bit int. What is printed?

Assume 32-bit int. What is printed?
int x = -5;
printf("%d", x & 1);
  1. A. -1
  2. B. 0
  3. C. 5
  4. D. 1

Correct answer: D. 1

-5 in two's complement is ...11111011. ANDing with 1 extracts the least significant bit, which is 1 (since -5 is odd); the result of & with operand 1 is always 0 or 1, never negative.

More C Programming questions

Exams that ask this topic