ProgrammingModerateInfosys · Wipro

What is printed?

What is printed?
#include <stdio.h>
int main(void) {
    int x = 6;
    printf("%d", x & -x);
}
  1. A. 2
  2. B. 6
  3. C. 4
  4. D. 8

Correct answer: A. 2

x & -x keeps only the lowest set bit of 6 = 110, which is 10 = 2. The value 4 is the highest set bit, not the lowest.

More C Programming questions

Exams that ask this topic