Difficulty: Easy
Correct Answer: 8
Explanation:
Introduction / Context:
This question tests understanding of C's sizeof operator and the effect (or lack of effect) of cast expressions that are not used. In classic 16-bit DOS compilers like Turbo C, the size of fundamental types can differ from today’s 32/64-bit compilers. Here, we focus on what actually gets printed and why the cast chain does not change the result.
Given Data / Assumptions:
double i;printf("%d", sizeof(i));(int)(float)(char) i; whose value is not used.
Concept / Approach:
The sizeof operator returns the size, in bytes, of its operand’s type at compile time. Unused cast expressions are evaluated only for their value category/type (and may be optimized away); they do not change the type or size of the declared object. On Turbo C, sizeof(double) is typically 8 bytes.
Step-by-Step Solution:
1) Identify the printed expression: sizeof(i) equals sizeof(double). 2) On Turbo C (16-bit), sizeof(double) is 8. 3) The cast chain forms a temporary value and is discarded; it does not alter i. 4) Therefore, the program prints 8.
Verification / Alternative check:
Remove the cast line entirely; the output remains the same because sizeof(i) depends only on i’s type, not on prior unused expressions.
Why Other Options Are Wrong:
4: On Turbo C, double is not 4 bytes. 16/22: These sizes do not match Turbo C's double. 0: sizeof never returns zero for an object type.
Common Pitfalls:
Assuming sizeof(double) is always the host’s modern 8/16 bytes; conflating type conversions with object size; believing that an unused cast changes the variable’s type.
Final Answer:
8
Discussion & Comments