ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
int i = 3.99;
int j = -3.99;
int k = (int)(0.29 * 100);
printf("%d %d %d", i, j, k);
  1. A. 3 -4 29
  2. B. 3 -3 28
  3. C. 4 -4 29
  4. D. 3 -3 29

Correct answer: B. 3 -3 28

Converting a floating value to int truncates toward zero: 3.99 → 3 and -3.99 → -3 (not -4). 0.29 has no exact binary representation; the double nearest to it is slightly below 0.29, so 0.29 * 100 evaluates to 28.999999999999996 and truncation gives 28, not 29. Use round() or add 0.5 before converting when you mean rounding.

More C Programming questions

Exams that ask this topic