C Programming - Complicated Declarations - Discussion

Discussion Forum : Complicated Declarations - Find Output of Program (Q.No. 3)
3.
What will be the output of the program?
#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, 4
2, 2, 2
2, 8, 4
2, 4, 8
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
31 comments Page 1 of 4.

Vijay said:   1 decade ago
Near pointer : If the size of the program is very large the program may create a near pointer to a piece of frequently accessed memory so as to enhance performance.

But I am curious to know that so the near pointer is allocated/ created by the system rather than the user.

Far pointer: If the program requires a lot of data, then a separate space is allocated for it outside the program data segment. So then a far pointer is used to access these memory locations so that the speed remains fast.

Huge pointer: In an 8086 family of processors, the max. Size of one data item can be 64k. But to override this default setup we can make use of huge pointers to have an object of size larger than 64k.

Sun yijia said:   7 years ago
There are only there pointers(ptr1,ptr2,ptr3), we can regard them to 3 level pointers.

Example ptr1----> char * * * ptr1,------> char huge* * * ptr1 ------> char huge* near* *ptr1-----> char huge* near* far* ptr1.

Every level represents different pointer types.

So , there is the same answer, **ptr1/ptr2/*ptr3 are the huge pointer type.

Shashi said:   1 decade ago
Treat expression as pointer pointing to pointer.

E.g. char huge*near*far*ptr1 means ptr1 points to far type (or say address of far type) ; far is again pointing to near type and near to huge.

Thus ptr--> 4 bytes (far)
*ptr-->2 bytes (near)
**ptr-->4 bytes (huge)

This happened becausse associativity of pointer is right to left.

Pavan said:   1 decade ago
Exp: far, near and huge pointer are used in dos only. Because there is only one mb memory for accessing. 1mb memory is divided into segment.

There are various segment like cs(code segment), ss(stack segment), ds(data segment) and more like extra segment etc.

Such type of pointer are used to access the memory.

Rohith said:   10 years ago
Hey guys lets see this in a simple way. As C program is platform dependent first it goes to far which is inside near and as far will take 4 bytes it will take four bytes and last inside near there is far near is 2 bytes but is 4 bytes so it will take 4 bytes.

SHUBHAM AGNIHOTRI said:   1 decade ago
char huge *near *far *ptr1;
here *ptr1 is huge pointer
here **ptr1 is near pointer
here ***ptr1 is far pointer.

Nw take it similarly in al.l cases & the o/p is justified .

Kiran said:   1 decade ago
Huge *far *near *ptr1---> is this a single variable?

If it is a single variable we should not use spaces in b/w the variables?

Can any one give me the explination please?

Sumasree said:   1 decade ago
It's supports multiple languages and also portable runs on all available platforms and free s/w, but turbo C don't have these all.

Pranali said:   8 years ago
@Monika

Nope, if we write as,

int *p;
pf("%d",sizeof(p));

it will shows size of '*'i.e. pointer not of 'int'.

Abhijit_softlove said:   1 decade ago
char x *y *z *ptr; / x y &z near huge or far

sizeof(ptr)= sizeof(z)
sizeof(*ptr)= sizeof(y)
sizeof(**ptr)= sizeof(x)


Post your comments here:

Your comments will be displayed after verification.