C Programming - Complicated Declarations - Discussion

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

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
Explanation:
No answer description is available. Let's discuss.
Discussion:
32 comments Page 1 of 4.

Rampa said:   1 decade ago
There is something known as memory segment for near it saves relative memory and far and huge it saves absolute memory.

For a 32 bit machine memory bus width is 32 bit that means it can support maximum of 2^32 capacity that is 4Gb memory. In the sense to store address of any byte in absolute form we need 32 bit pointer (full address). But in near there will be something base pointer (internally) which stores 32 bit address and all other pointer which we declare stores only relative address that is 2 bytes. For example if base has 10000000h address and p=ffffh (where p is pointer) then absolute address of p is 10000000h+ffffh=1000ffffh. Where base address contains the starting address of a near segment.

Shubham Mittal said:   5 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:   6 years ago
Huge~4;
Far~4;
Near~2;

Divya said:   6 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:   6 years ago
Can anyone explain in detail to me?

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

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

Sahithi said:   8 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):

Near:
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.

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

Huge:
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:   8 years ago
Huge = 4.
Far = 4.
Near = 2.

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

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


Post your comments here:

Your comments will be displayed after verification.