Difficulty: Easy
Correct Answer: 7
Explanation:
Introduction / Context:Casting from float to int truncates toward zero. Printing with %d expects an int value. This question checks understanding of truncation versus rounding.
Given Data / Assumptions:
Concept / Approach:Use the truncation rule: for positive numbers, truncation is equivalent to floor; for negative numbers, truncation differs from floor.
Step-by-Step Solution:Compute (int)7.29 → 7.printf prints 7.
Verification / Alternative check:Testing with a negative value, e.g., (int)(-7.29) would yield -7 (truncation), whereas floor(-7.29) would be -8.
Why Other Options Are Wrong:0, 0.0, 7.0: not consistent with truncation and %d formatting.
Common Pitfalls:Confusing rounding with truncation; using the wrong printf format specifier.
Final Answer:7
Discussion & Comments