C Programming - Complicated Declarations - Discussion

Discussion Forum : Complicated Declarations - Find Output of Program (Q.No. 4)
What will be the output of the program (in Turbo C under DOS)?

int main()
    char huge *near *far *ptr1;
    char near *far *huge *ptr2;
    char far *huge *near *ptr3;
    printf("%d, %d, %d\n", sizeof(ptr1), sizeof(ptr2), sizeof(ptr3));
    return 0;
4, 4, 8
2, 4, 4
4, 4, 2
2, 4, 8
Answer: Option
No answer description is available. Let's discuss.
32 comments Page 1 of 4.

Shubham Mittal said:   3 years ago
Far pointer size 32 bytes = 4 bit.
Huge pointer size 32 bytes = 4 bit.
Near pointer size 32 bytes = 2 bit.

So, the answer is= 4, 4, 2.

Nivedita.s.j said:   3 years ago

Divya said:   4 years ago
Chat huge *near *far *ptr1;
Ptr1= far so 4// check from right to left.

char near *far *huge *ptr2;
*Ptr2= far so 4// one star so second is taken.
char far *huge *near *ptr3;
**Ptr3=far so 4.

Manohr said:   4 years ago
Can anyone explain in detail to me?

Gitpr said:   5 years ago
Why can't I find huge near or far on cppref? Please explain.

Nawaz said:   5 years ago
I am not getting how it is taking size? So please anyone explain this in detail.

Sahithi said:   6 years ago
When working on architectures with segmented memory (like x86 real mode), one can distinguish three types of pointer addresses (examples for x86 in segment:offset notation):

Only stores the offset part (which is 16-bit) - when resolving such a pointer, the current data segment offset will be used as segment address.

Stores segment and offset address (16 bit each), thus defining an absolute physical address in memory.

Same as far pointer, but can be normalized, i.e. 0000:FFFF + 1 will be wrapped around appropriately to the next segment address.

Ajay Paratmandali said:   6 years ago
Huge = 4.
Far = 4.
Near = 2.

Ptr1-far *ptr1-near **ptr1-huge.
Ptr2-huge *ptr2-far **ptr2-near.
Ptr3-near *ptr3-huge **ptr3-far.

Aparna said:   6 years ago
Unable to understand please someone explain in steps.

Krishnaveni said:   7 years ago
I can't understand. It's so confusing. Please explain me clearly.

Post your comments here:

Your comments will be displayed after verification.