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

Ravi said:   1 decade ago
Think it like this :
ptr1 is a far pointer to a near pointer to a huge pointer to char .
Think arrow (->) sign as "pointing to" :
ptr1 (far type) -> *ptr1 (near type) -> **ptr1(huge type) -> ***ptr1 (char type)
Now
sizeof(ptr1)= far pointer size = 4 bytes
sizeof(*ptr1)= near pointer size = 2 bytes
sizeof(**ptr1)= huge pointer size = 4 bytes

Gautam A Naik said:   1 decade ago
But why is sizeof (ptr3) will give output as 2?. please explain me.

Deepika said:   1 decade ago
All the varibles have same type ouput is 4,4,4 but output is 4,4,2

SandeepaSri said:   1 decade ago
Explanation please.

Somnath said:   1 decade ago
ptr1 is a pointer to a far pointer for that the size is 4
ptr2 is a pointer to a huge pointer for that the size is 4
ptr3 is a pointer to a near pointer for that the size is 2

Seshan said:   1 decade ago
I can't understand can you explain me with full reference.

Sarfraj said:   1 decade ago
I m not able to understand that, please give more explanation.

Sai said:   1 decade ago
it will consider the *far *ptr1---------------- * far 4bytes
*huge *ptr2--------------- *huge 4 bytes
*near *ptr3 -----------------near 2 bytess

Kumar said:   1 decade ago
@NN

The above code works fine in Turbo C as said.

But in GCC it not works.

Is this due to platform dependency of C compiler?

Can you explain please?

N n said:   1 decade ago
The code has syntax errors.


Post your comments here:

Your comments will be displayed after verification.