In 16-bit DOS memory models, how many bytes are used by near, far, and huge pointers respectively?

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:

  • Platform is 16-bit DOS with segment:offset addressing.
  • near pointers reference within a single segment.
  • far and huge pointers include both segment and offset.


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:

  • near=2 far=4 huge=8: Huge is not 8 bytes in 16-bit DOS.
  • near=4 far=8 huge=8 or near=4 far=4 huge=8: These sizes correspond to neither 16-bit DOS nor standard models.


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.

More Questions from Pointers

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion