Difficulty: Easy
Correct Answer: 2 on a 16-bit compiler, 4 on a 32-bit compiler
Explanation:
Introduction / Context:
This question probes the relationship between pointer size and platform/ABI, not the pointee type. The sizeof operator reports the storage size of the pointer itself.
Given Data / Assumptions:
Concept / Approach:
In C, pointer size depends on the target architecture and memory model, not on the pointed-to type. Therefore, sizeof(float*) equals sizeof(void*) on a given platform. Classic DOS 16-bit compilers generally produce 2-byte near pointers, while 32-bit systems use 4-byte pointers. Modern 64-bit ABIs usually use 8-byte pointers (not listed among the choices).
Step-by-Step Solution:
Declare float *p; compute sizeof(p).On 16-bit model → 2 bytes; on 32-bit model → 4 bytes.Note: This holds regardless of float vs int pointer.
Verification / Alternative check:
Print sizeof on target systems; observe that all object pointers share the same size within an ABI.
Why Other Options Are Wrong:
The pointee type does not affect pointer size, making options that swap sizes incorrect. “Always 8” generalizes from 64-bit only and ignores older ABIs.
Common Pitfalls:
Assuming pointer size equals sizeof(pointee); forgetting that %d for sizeof should be cast to int or printed with %zu for size_t.
Final Answer:
2 on a 16-bit compiler, 4 on a 32-bit compiler
Discussion & Comments