ProgrammingHardWipro · Cognizant pattern

What is printed?

What is printed?
int x = 101;
int y = (x >> 2) << 2;
printf("%d", y);
  1. A. 101
  2. B. 100
  3. C. 96
  4. D. 99

Correct answer: B. 100

101 = 0b1100101. x>>2 = 25 (0b11001), discarding the low 2 bits (01). Shifting left by 2 appends two zero bits: 25<<2 = 100, not 101 — the original low bits are lost, rounding 101 down to the nearest multiple of 4, which is 100.

More C Programming questions

Exams that ask this topic