Turbo C (DOS): evaluate sizeof results that mix pointer levels and dereferences:
#include
int main()
{
char huge *near *far *ptr1;
char near *far *huge *ptr2;
char far *huge *near *ptr3;
printf("%d, %d, %d
", sizeof(ptr1), sizeof(*ptr2), sizeof(*ptr3));
return 0;
}
-
A4, 4, 4
-
B2, 4, 4
-
C4, 4, 2
-
D2, 4, 8
Answer
Correct Answer: 4, 4, 4
Explanation
Introduction / Context:This problem combines multi-level pointers with near/far/huge qualifiers and requires resolving the type at each dereference before applying sizeof in Turbo C (16-bit DOS).
Given Data / Assumptions:
- near = 2 bytes; far = 4 bytes; huge = 4 bytes.
- ptr1 is far; ptr2 is far; *ptr3 is far.
Concept / Approach:Unwrap one level at a time and record the qualifier at that level. sizeof reports the size of the pointer representation at the evaluated type.
Step-by-Step Solution:1) sizeof(ptr1): ptr1 is far * ⇒ 4.2) sizeof(*ptr2): ptr2 is huge * to (far *) ⇒ *ptr2 is far * ⇒ 4.3) sizeof(**ptr3): ptr3 is near * to (huge * to (far *)) ⇒ **ptr3 is far * ⇒ 4.4) Therefore the output is 4, 4, 4.
Verification / Alternative check:Print intermediate sizeof values for *ptr2 and **ptr3 to confirm both are far pointers.
Why Other Options Are Wrong:Options B/C/D: Misidentify which level is being measured by sizeof or assume an incorrect 2-byte result.
Common Pitfalls:Jumping directly to the base char type instead of recognizing that dereferencing here still yields a pointer type.
Final Answer:4, 4, 4