ProgrammingHardTCS NQT · Infosys

Would the product of 50000 and 50000 overflow a 32-bit int? The program checks with a 64-bit product. What is printed?

Would the product of 50000 and 50000 overflow a 32-bit int? The program checks with a 64-bit product. What is printed?
#include <stdio.h>
int main(void) {
    long long p = (long long)50000 * 50000;
    printf("%d", p > 2147483647LL);
}
  1. A. 0
  2. B. 2
  3. C. 3
  4. D. 1

Correct answer: D. 1

The product is 2500000000, which is larger than INT_MAX = 2147483647, so the comparison is 1.

More C Programming questions

Exams that ask this topic