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 2 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.
Harsha said:
1 decade ago
What actually mean near, far and huge pointers ?
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.
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
Anil said:
1 decade ago
But how? can anyone explain this one.
Chintu said:
1 decade ago
Please explain about this problem, and also define huge, far, near.
Pravin said:
1 decade ago
Please give the explanation about this problem.
Suresh said:
1 decade ago
Any pointer will take size 4bits in 64 bit compiler, 2 bits in 32 bit compiler.
Ravikumar said:
1 decade ago
Give the explanation of the answer......
Kishore said:
1 decade ago
Explanation please.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers