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 3 of 4.

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.

Meerb said:   1 decade ago
Please me the answer of this question please.

What will be the size of a pointer, pointing to an object of size 1MB?

Riya said:   10 years ago
If near pointer is 2 byte then why the output is 4 byte for ptr 2.

Jayshree said:   10 years ago
I am confused about output can you explain anyone again!

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.

Monika said:   9 years ago
The %d is used for integers so it will show the size of int.

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'.

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.

Parth barde said:   7 years ago
Thank you all for explaining the solution.

Mikkawy said:   5 years ago
@Naseeb.

GCC (Gnu Compiler Collection).


Post your comments here:

Your comments will be displayed after verification.