Turbo C (DOS) pointer sizes: predict the output for these declarations and sizeof calls:\n\n#include<stdio.h>\n\nint main()\n{\n char far *near *ptr1; // near pointer\n char far *far *ptr2; // far pointer\n char far *huge *ptr3; // huge pointer\n printf("%d, %d, %d\n", sizeof(ptr1), sizeof(ptr2), sizeof(ptr3));\n return 0;\n}

Difficulty: Medium

Correct Answer: 2, 4, 4

Explanation:


Introduction / Context:
The task is to bind qualifiers correctly and recall that in Turbo C, near pointers are 2 bytes while far/huge pointers are 4 bytes. sizeof returns the storage size of the pointer variable itself.


Given Data / Assumptions:

  • near = 2; far = 4; huge = 4 bytes.
  • Qualifiers next to the identifier set that pointer's representation.


Concept / Approach:
Read from the identifier outwards. The outermost qualifier adjacent to ptr1/ptr2/ptr3 governs their sizes.


Step-by-Step Solution:
1) ptr1 is a near pointer ⇒ sizeof = 2.2) ptr2 is a far pointer ⇒ sizeof = 4.3) ptr3 is a huge pointer ⇒ sizeof = 4.4) Output: 2, 4, 4.


Verification / Alternative check:
Isolate the declarations and print sizeof individually; results will match.


Why Other Options Are Wrong:
Option A/D: Introduce an 8-byte size which Turbo C does not use for these pointers.
Option B: Treats near as 4 bytes, which is incorrect.


Common Pitfalls:
Assuming inner levels affect the outermost pointer size for sizeof; they do not.


Final Answer:
2, 4, 4

More Questions from Complicated Declarations

Discussion & Comments

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