Difficulty: Medium
Correct Answer: near=2 far=4 huge=4
Explanation:
Introduction / Context:
Legacy 16-bit DOS compilers (e.g., Turbo C) used segmented memory. Pointer size depended on the model: near, far, and huge pointers referenced memory differently across segments and offsets. Recognizing these sizes is vital for understanding historical code and interview questions about memory models.
Given Data / Assumptions:
Concept / Approach:
A near pointer holds only a 16-bit offset (2 bytes). Far and huge pointers store a 16-bit segment and a 16-bit offset, totaling 32 bits (4 bytes). The difference between far and huge is semantic: huge pointers are normalized for arithmetic across segment boundaries, whereas far pointers are not necessarily normalized, but both are 4 bytes.
Step-by-Step Solution:
Identify near pointer size: offset only → 2 bytes.Identify far/huge pointer sizes: segment (2 bytes) + offset (2 bytes) → 4 bytes.Conclude: near=2, far=4, huge=4.Recognize behavioral difference (normalization) without affecting size.
Verification / Alternative check:
Consulting old compiler docs (e.g., Borland/Turbo C memory models) confirms 2-byte near and 4-byte far/huge pointers in 16-bit modes.
Why Other Options Are Wrong:
Common Pitfalls:
Confusing 32/64-bit flat models (where pointers are 4/8 bytes) with 16-bit segmented models. Always tie pointer size to architecture and memory model.
Final Answer:
near=2 far=4 huge=4.
Discussion & Comments