ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
#include <stdio.h>
int main(void) {
    int x = 5;
    int *p = &x;
    *p = *p << 2 | 1;
    printf("%d", x);
}
  1. A. 20
  2. B. 22
  3. C. 21
  4. D. 17

Correct answer: C. 21

Shift binds tighter than bitwise OR, so the value is (5 << 2) | 1 = 20 | 1 = 21. The write through p updates x.

More C Programming questions

Exams that ask this topic