ProgrammingHardTCS NQT · Accenture

What is printed?

What is printed?
#include <stdio.h>
int main(void) {
    long long a = 1LL << 40;
    int b = (int)(a >> 20);
    printf("%d", b);
}
  1. A. 1099511627776
  2. B. 0
  3. C. 2097152
  4. D. 1048576

Correct answer: D. 1048576

a >> 20 is 2^40 / 2^20 = 2^20 = 1048576, which fits in int, so the conversion is exact.

More C Programming questions

Exams that ask this topic