Based on the memory model and segment, pointers are divided into three types -
is a pointer that works within the 64Kb memory data segment range.
It cannot access addresses beyond this data segment.
Near pointers can be incremented or decremented by using the address range arithmetic operators.
Using the keyword near, we can set any pointer to a near pointer.
The syntax is as follows-
<data type> near <pointer definition> <data type> near <function definition>
The following statement declares the near pointer of variable s
char near *string;
The following program shows the usage of near pointers.
#include<stdio.h> int main(){ int number=50; int near* p; p=&number; printf("%d",sizeof(p)); return 0; }
The output is as follows-
2
It is a pointer, which stores different pointers offset and segment address.
It has access to all 16 segments.
The far pointer address range is 0 to 1MB.
When the pointer is incremented or decremented, only the offset part changes.
The syntax is as follows-
<data type> far <pointer definition> <data type> far <function definition>
The following statement declares the far pointer of variable s
char far *s;
The following program shows the usage of far pointers.
#include<stdio.h> int main(){ int number=50; int far *p; p=&number; printf("%d",sizeof number); return 0; }
The output is as follows -
4
It is a size similar to that of a far pointer Pointers, since both are 32-bit addresses.
Large pointers can be incremented without being affected by segment work loops.
The following program shows the use of large pointers.
#include<stdio.h> Int main(){ Char huge *far *ptr; Printf("%d%d%d",sizeof(ptr),sizeof(*ptr),sizeof(**ptr)); Return 0; }
The output is as follows -
4 4 1
The above is the detailed content of Explain Near, Far and Huge pointers in C language. For more information, please follow other related articles on the PHP Chinese website!