ProgrammingModerateTCS NQT · Infosys

What is printed?

What is printed?
int a = 6, b = 2;
int r = a & 3 << b | 1;
printf("%d", r);
  1. A. 13
  2. B. 5
  3. C. 9
  4. D. 0

Correct answer: B. 5

Precedence is << then & then |, so r = (6 & (3 << 2)) | 1 = (6 & 12) | 1 = 4 | 1 = 5. Reading left to right, ((6 & 3) << 2) | 1, gives 9; 13 ignores the & altogether (12 | 1).

More C Programming questions

Exams that ask this topic