ProgrammingHardIBM · Deloitte pattern

What is printed?

What is printed?
int main(void) {
    int x = 100;
    long y = x;
    long long z = y * 1000000000L;
    printf("%lld", z);
}
  1. A. -2147483648
  2. B. Compilation error: cannot multiply long by long long literal
  3. C. 100000000000
  4. D. 0

Correct answer: C. 100000000000

y (long) * 1000000000L (also long, due to the L suffix) is computed in long precision; on this 64-bit LP64 ABI, long is 8 bytes, so 100 * 1000000000 = 100000000000 fits without overflow, and assigning to the (also 64-bit) long long z preserves it exactly.

More C Programming questions

Exams that ask this topic