ProgrammingHardWipro · Cognizant pattern

Assume 32-bit int. What is printed?

Assume 32-bit int. What is printed?
int x = 3;
int y = 1 << x | 1;
printf("%d", y);
  1. A. 9
  2. B. 8
  3. C. 17
  4. D. 2

Correct answer: A. 9

<< has higher precedence than |, so 1 << x | 1 parses as (1 << x) | 1 = (1 << 3) | 1 = 8 | 1 = 9 (binary 1000 | 0001 = 1001).

More C Programming questions

Exams that ask this topic