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

Vishwanath said:   2 years ago
Hello, Anyone, please explain the problem solution.

Mikkawy said:   4 years ago
@Naseeb.

GCC (Gnu Compiler Collection).

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

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.

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

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

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

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

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

Meerb said:   10 years ago
Please me the answer of this question please.

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


Post your comments here:

Your comments will be displayed after verification.