ProgrammingHardWipro · Cognizant pattern

Assume 32-bit int. What is printed?

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

Correct answer: C. 1

x & -x isolates the LOWEST set bit of x. 5 is 0101; -5 in two's complement is ...11111011; ANDing them gives 0001 = 1, which is exactly 5's lowest set bit (the '1' bit).

More C Programming questions

Exams that ask this topic