//The output for this code is observed to be 4 4 2 ? I dont get why is it 2 for ptr3?please help
#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;
}
near,far, andhugepointers are non-standard.In implementations that support them (usually for very old x86 systems), a specific location in memory can be specified by a segment and an offset. A
nearpointer contains only an offset, leaving the segment implicit. Thus it requires less space than afarpointer.Modern compilers do not use any of these keywords. I suggest you find yourself a newer compiler; there are plenty of free ones available.
See this question for more information.
Incidentally, printf’s
"%d"format requires an argument of typeint;sizeofyields a result of typesize_t, which is a different type. You can change yourprintfcall to:(The modern way to do that is:
but an implementation that supports
nearandfarpointers isn’t likely to be modern enough to support"%zu", which was introduced in C99.)