C Programming - Complicated Declarations - Discussion

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

Bhavana said:   1 decade ago
Can any1 explain me this stuff......:)

Praveen said:   1 decade ago
Can any one explain ?

Saravana kumar said:   1 decade ago
Explain me please.

Ravi raushan said:   1 decade ago
As we know pointer size is 2 bytes(offset value), but far&huge pointer has two part 16-bit:segment value as well as offset value.

The 'near' is having only segment value,so ptr1 size is 4 byte,**ptr2 size is 2 byte, pr3 size is 2 byte.

Satheesh said:   1 decade ago
Can anyone explain this code in detail?

Dhaval said:   1 decade ago
Can anyone explain the flow of operations going and how the answer is coming to 4.

Raj said:   9 years ago
Here basic and easy rule.

Near - 2 bytes, huge - 4 bytes, far -4 bytes.

char huge *near *far *ptr1;

printf ("%d %d %d\n", sizeof (ptr1), sizeof (*ptr1), sizeof (**ptr1));

// Understand this.

// char (huge=**ptr1)(*near==*ptr1)(*far==ptr1)*ptr1;

O/P:

1st ptr1-> 4.
2nd ptr1 -> 2.
3rd ptr1-> 4.

Bharathi said:   9 years ago
How near, huge and far is assigned 2 or 4 bytes?

King_07 said:   9 years ago
Is there any detailed explanation? I'm sorry but all explanation are not clear.

Thank you.

Prabha said:   9 years ago
Please explain clearly?


Post your comments here:

Your comments will be displayed after verification.