Difficulty: Easy
Correct Answer: Correct
Explanation:
Introduction / Context:
Type sizes in C are implementation-defined and can vary across platforms and ABIs. The language provides the sizeof operator to query object sizes at compile time (and also usable in constant expressions). This question checks whether sizeof is the correct portable way to discover sizes for short int and long int.
Given Data / Assumptions:
Concept / Approach:
sizeof(type) yields the size in bytes of any complete object type. It is evaluated at compile time for known types and is the standard mechanism for determining the storage size without resorting to non-portable tricks. This works equally for short, int, long, pointers, structures, and arrays (with caveats for flexible array members).
Step-by-Step Solution:
Verification / Alternative check:
Compare the values with limits macros from
Why Other Options Are Wrong:
Common Pitfalls:
Assuming fixed sizes (e.g., long always 8 bytes). Always use sizeof for portability.
Final Answer:
Correct.
Discussion & Comments