C Programming - Complicated Declarations - Discussion

Discussion Forum : Complicated Declarations - Find Output of Program (Q.No. 6)
6.
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, 4, 4
4, 4, 2
2, 4, 8
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
21 comments Page 1 of 3.

Amit said:   3 years ago
Pointer in 16-bit compiler is 2 byte.
32-bit compiler have 4 byte.
64-bit compiler have 8 byte.

Srikar said:   6 years ago
Thanks @Anurag.

Sakshi said:   6 years ago
Near pointer-- this pointer created in one segment and holding any offset address of the same segment or the pointer that works under 64KB is called the near pointer.

Far pointer--the pointer created in one segment and holding the offset address of the other segment or the pointer that works beyond 64KN memory is called far pointer.

Huge pointer--it is the same as the far pointer but it always normalises the address before reading or writing data into memory.

Alia said:   8 years ago
Please explain this.

Shyam said:   8 years ago
What is the diff used to find whether a question is 32/64bit?

Payal said:   9 years ago
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));

:when ptr1 is called it will type cast near to far then huge and return 4.
:when *ptr2 is called same type cast near to far then huge and return 4.
:when **ptr3 is called it will type cast again far too huge then to near but this time ptr to ptr is called n it is pointing to far type so return 4 again.
(1)

Radha said:   10 years ago
Please to solve the program. I need answer.

Manivas said:   1 decade ago
On 32-bit machine sizeof pointer is 32 bits (4 bytes), while on 64 bit machine it's 8 byte. Regardless of what data type they are pointing to, they have fixed size.

Mani said:   1 decade ago
Pointer size in 64 bit is 4 bits.

SUHAS T M said:   1 decade ago
Pointer is used to store the address of int, char, float so no matter what the data type is. It stores the address value which is an integer value so it requires 2 byte in 16 bit compiler and 4 byte in 32 bit compiler.


Post your comments here:

Your comments will be displayed after verification.