C Programming - Complicated Declarations - Discussion

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

Krishnaveni said:   9 years ago
I can't understand. It's so confusing. Please explain me clearly.

Ashwini said:   9 years ago
Can't understand it. Explain it more detail.

Arusha said:   9 years ago
Can't understand it. Explain.

Divya said:   9 years ago
Don't understand the concept of near far huge pointers. Help me by explaining this.

Priyanka said:   1 decade ago
Irrespective of pointer it declares far is of size 4,

Huge is of size 4,

Near is of size 2.

Rohit said:   1 decade ago
#include<stdio.h>

int main()
{
char huge *near *far *ptr1;
printf("%d %d\n", sizeof(***ptr1),sizeof(****ptr1));
return 0;
}

Deepak said:   2 decades ago
Please explain this to me.

Hany said:   1 decade ago
Why we consider the size of far, huge and near as 4, 4 and 2 respectively. Then in declaration of first line also there is near so why it takes 4bytes of size?

Kavi said:   1 decade ago
What is the purpose of near, huge and far pointers. Explain with an example program?

Adarsh said:   1 decade ago
Actually far and near are related to fact that how we are accessing the variable i.e. absolute or relative.

Relative = "near";.

Absolute="far".

When we are accessing variable relative, then we hav to store only relative address that account for our 2 bytes of memory.

And the rest is understood.


Post your comments here:

Your comments will be displayed after verification.