C Programming - Complicated Declarations - Discussion

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

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

Paveen said:   4 years ago
Near used to store 16-bit address that is within the current segment.

While far & ptr typically used to store 32-bit address i.e. outside the current segment.

Rajarshi Deb said:   5 years ago
I an not understanding, please anyone explain.

Alfaz raza said:   9 years ago
Guys actually here they introduce three types of pointers, in which first one is near. This pointer can point within the segment or program.

Second one is far pointer it can point to outside the segment and also it can point to large range of address.

Third one is huge pointer it is similar to far pointer. In case of far pointer it is not possible to point to outside the certain boundary, whereas in case of huge pointer if programmer wants the value which is outside the boundary in that situation huge extends its capacity.

Sonia sonawane said:   9 years ago
void incr();
int main()
return 0;
void incr()
auto int i=1;

Jarvis said:   9 years ago
char near *near *ptr1;

This "near" does not help in anyway.

1. Try removing "that" near.

2. Try putting "far" or "huge" instead of "that".

=> the output is still same (2,4,4)

The question is why?

Lali said:   9 years ago
@Chilli can you explain how near always take 2 byte and far take 4 byte.

Sruthi said:   10 years ago
Size of pointer only depends on type on compiler but not on data type. But why this difference?

Deepika said:   1 decade ago
Why near variable takes 2bytes and other variable takes 4bytes but all the variables have same type.

Mayur said:   1 decade ago
Thanks chilli.

Chilli said:   1 decade ago
Near always takes 2 bytes.

Far and huge always takes 4 bytes.

Post your comments here:

Your comments will be displayed after verification.