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.

Anand Sharma said:   6 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:   7 years ago
Thanks @Raj.

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

Prabir said:   7 years ago
Simply remember.

*p=2
P=4
**p=4
***p=2
****p=4

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

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

Abhayraj SN said:   8 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.
(1)

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

Prabha said:   9 years ago
Please explain clearly?

King_07 said:   9 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.