Turbo C (DOS) pointer sizes: predict the output for these declarations and sizeof calls:
#include
int main()
{
char far *near *ptr1; // near pointer
char far *far *ptr2; // far pointer
char far *huge *ptr3; // huge pointer
printf("%d, %d, %d
", sizeof(ptr1), sizeof(ptr2), sizeof(ptr3));
return 0;
}
-
A4, 4, 8
-
B4, 4, 4
-
C2, 4, 4
-
D2, 4, 8
Answer
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