Near, Far, and Huge Pointers in C: Memory Models Explained
☰Fullscreen
Table of Content:
Near Pointer
- The pointer which can points only 64KB data segment or segment number 8 is known as near pointer.
- That is near pointer cannot access beyond the data segment like graphics video memory, text video memory, etc. Size of near pointer is two byte. With the help of keyword near, we can make any pointer as near pointer.
Example of Near Pointer
#include int main() { int x=25; int near* ptr; ptr=&x; printf(“%d”,sizeof ptr); return 0; }
Output: 2
Far Pointer
- The pointer which can point or access whole the residence memory of RAM, i.e., which can access all 16 segments is known as far pointer.
- Size of the far pointer is 4 byte or 32 bit.
Example of Far Pointer
#includeint main() { int x=10; int far *ptr; ptr=&x; printf("%d",sizeof ptr); return 0; }
Output : 4
Huge Pointer
- The pointer which can point or access whole the residence memory of RAM i.e. which can access all 16 segments is known as a huge pointer.
- Size of the far pointer is 4 byte or 32 bit.
Example of Huge Pointer
#includeint main() { char huge * far *p; printf("%d %d %d",sizeof(p),sizeof(*p),sizeof(**p)); return 0; }
Output : 4 4 1
Explanation: p is the huge pointer, *p is the far pointer and **p is char type data variable.