Turbo C memory models — sizes of near, far, and huge pointers (pointer-to-pointer declarations).\n\n#include<stdio.h>\n\nint main()\n{\n char near near ptr1; / near pointer to near char => near pointer size */\n char near far ptr2; / far pointer to near char => far pointer size */\n char near huge ptr3; / huge pointer to near char => huge pointer size /\n printf("%d, %d, %d\n", (int) sizeof(ptr1), (int) sizeof(ptr2), (int) sizeof(ptr3));\n return 0;\n}\n\nWhat is the output on Turbo C?

Difficulty: Medium

Correct Answer: 2, 4, 4

Explanation:


Introduction / Context:
In 16-bit Turbo C, pointer size depends on the memory model and the pointer qualifier: near (typically 16 bits), far (32 bits segment:offset), and huge (also 32 bits but normalized). This question asks for the sizes of pointers to pointer objects with different qualifiers.


Given Data / Assumptions:

  • ptr1 is a near pointer variable.
  • ptr2 is a far pointer variable.
  • ptr3 is a huge pointer variable.


Concept / Approach:
The size reported by sizeof(ptrX) is the size of the pointer variable itself, determined by its qualifier (near/far/huge). Near pointers are 2 bytes; far and huge pointers are 4 bytes in Turbo C. The pointee type (here, a near char) does not change the size of the pointer variable.


Step-by-Step Solution:

1) ptr1 is near => sizeof(ptr1) = 2.2) ptr2 is far => sizeof(ptr2) = 4.3) ptr3 is huge => sizeof(ptr3) = 4.


Verification / Alternative check:
Compiling with Turbo C in small/medium model yields these sizes. Changing the variable qualifiers (e.g., making the pointee far) would not affect sizeof(ptrX), which depends on the pointer variable's own qualifier.


Why Other Options Are Wrong:

  • 4,4,8 or 2,4,8: Huge pointers are 4 bytes, not 8, on Turbo C.
  • 4,4,4: Implies near is 4 bytes, which is incorrect for 16-bit near.


Common Pitfalls:
Confusing the qualifier placement in multi-level pointer declarations; remember sizeof applies to the variable's pointer type, not the target type's qualifier.


Final Answer:
2, 4, 4

More Questions from Complicated Declarations

Discussion & Comments

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