ProgrammingVery hardTCS NQT · Infosys · Product Company SDE

What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits)? #include <stdio.h> int main(void) { float f = 2.5f; int n = 4; printf("%d %d %d", (int)(f * n), (int)f / n, (int)(f / n)); return 0; }

  1. A. 8 0 0
  2. B. 10 0 1
  3. C. 10 0 0
  4. D. 11 1 0

Correct answer: C. 10 0 0

Casts truncate toward zero. (int)(f*n) = ⌊10⌋ = 10; (int)f / n is integer division 2/4 = 0; (int)(f/n) = ⌊0.625⌋ = 0.

More C Programming questions

Exams that ask this topic