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;
}
Discussion:
21 comments Page 1 of 3.
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.
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.
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)
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.
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.
Anurag.jnn@gmail.com said:
1 decade ago
ptr1 is a pointer to a far pointer for that the size is 4 in 32 and 64 bit compiler.
ptr2 is a pointer to a huge pointer for that the size is 4 in 32 and 64 bit compiler.
ptr3 is a pointer to a near pointer for that the size is 2 in 32 bit and 4 in 64 bit compiler.
ptr2 is a pointer to a huge pointer for that the size is 4 in 32 and 64 bit compiler.
ptr3 is a pointer to a near pointer for that the size is 2 in 32 bit and 4 in 64 bit compiler.
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.
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.
Karthick said:
1 decade ago
near-2bit ...far and huge-4bit
far:sizeof(ptr1)-4 ... huge:sizeof(*ptr2)-4.... if it is
near:sizeof(*ptr3)-2 but here is near:sizeof(**ptr3)-4
far:sizeof(ptr1)-4 ... huge:sizeof(*ptr2)-4.... if it is
near:sizeof(*ptr3)-2 but here is near:sizeof(**ptr3)-4
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.
32-bit compiler have 4 byte.
64-bit compiler have 8 byte.
Suresh said:
1 decade ago
Any pointer will take size 4bits in 64 bit compiler, 2 bits in 32 bit compiler.
Chintu said:
1 decade ago
Please explain about this problem, and also define huge, far, near.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers