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.

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)

Archan said:   1 decade ago
"Near" and "far" pointers are actually non-standard qualifiers that you'll find only on x86 systems. They reflect the odd segmentation architecture of Intel processors. In short, a near pointer is an offset only, which refers to an address in a known segment. A far pointer is a compound value, containing both a segment number and an offset into that segment. Segmentation still exists on Intel processors, but it is not used in any of the mainstream 32-bit operating systems developed for them, so you'll generally only find the "near" and "far" keywords in source code developed for Windows 3.x, MS-DOS, Xenix/80286, etc.

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?

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

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

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.


Post your comments here:

Your comments will be displayed after verification.