C Programming - Complicated Declarations - Discussion

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

Anand Sharma said:   5 years ago
As pointer contains address (hexadecimal) values not simple integer or char values.

Thus the size of any pointer is 8 bytes.

Plo said:   6 years ago
Thanks @Raj.

Pranav said:   6 years ago
Someone, please explain this question in simple way.

Prabir said:   6 years ago
Simply remember.


Gary said:   7 years ago
Did not understand. Give some more eg.

Chitturi bhavani said:   7 years ago
I did not understand, can some one please explain me in detail?

Abhayraj SN said:   7 years ago
Kindly note it carefully.

Near pointer = 2 bytes,
far = 4 bytes,
huge = 4 bytes.

consider given one statement ---- char huge *near *far *ptr1;
sizeof(ptr1) -->> far = 4
sizeof(*ptr1) -->> near = 2
sizeof(**ptr1) -->> huge = 4

As * is included REVERSE back from the END in the statement.
Hope, you will get it. Thanks.

Geetha said:   7 years ago
I didn't understand this. Please explains briefly.

Prabha said:   8 years ago
Please explain clearly?

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

Thank you.

Post your comments here:

Your comments will be displayed after verification.