ProgrammingHardWipro · Cognizant pattern

Assume 32-bit int. What is printed?

Assume 32-bit int. What is printed?
int x = 100;
int y = x << 1;
int z = x >> 1;
printf("%d %d", y, z);
  1. A. 200 50
  2. B. 50 200
  3. C. 100 100
  4. D. 200 100

Correct answer: A. 200 50

Left-shifting by 1 multiplies by 2 (for values that don't overflow): 100 << 1 = 200. Right-shifting a positive value by 1 divides by 2, truncating toward zero in this case since the value is already a clean even number: 100 >> 1 = 50.

More C Programming questions

Exams that ask this topic