Far Pointer
A 32-bit far pointer can reach memory outside of the current segment. The compiler creates a segment register for segment address and another register for offset inside the current segment to make use of this.
In general, a Far pointer is thought to be a 32-bit pointer. It may, however, use the current segment to retrieve information stored outside the computer's memory. Although we usually need to allocate the sector register to hold the data address in the current segment to utilize this sort of pointer. In addition, another register must be set aside to hold offset inside the current segment.
Syntax of Far Pointer in C
<data type> far <pointer definition>

You can also try this code with Online C Compiler
Run CodeExample of Far Pointer in C
C
#include <stdio.h>
int main()
{
int num=20;
int far* ptr;
ptr=#
printf("%d",sizeof num);
return 0;
}

You can also try this code with Online C Compiler
Run Code
Output:
4
A Far pointer for the variable S is declared in the following statement
char far *s;
Some important points about Far Pointer are as follows:-
- Only the offset component of the pointer is modified when it is increased or decremented.
- It's a pointer that holds both the offset and the segment address that the pointer is comparing.
- A far pointer address might be somewhere between 0 and 1MB.
- All 16 segments are accessible.
Huge Pointer
Huge pointers have the same 32-bit size as far pointers and may reach bits outside the sector. Far pointers are fixed, and the sector in which they are situated cannot be changed; however, huge pointers may.
Like a far pointer, a huge pointer is usually 32 bits and may access the outer segment. A segment is fixed in the case of far pointers. The segment component of the far pointer cannot be changed; however, it can be changed in case of a huge pointer.
Syntax of Huge Pointer in C
In C, "huge pointers" don't have a distinct syntax defined by the language itself. However, the concept of "huge pointers" typically refers to far pointers in older versions of C, especially in the context of MS-DOS programming or segmented memory models.
Example of Huge Pointer in C
C
#include <stdio.h>
int main()
{
char huge * far *ptr;
printf("%d %d %d",sizeof(ptr),sizeof(*ptr),sizeof(**ptr));
return 0;
}

You can also try this code with Online C Compiler
Run Code
Output:
4 4 1

You can also try this code with Online C Compiler
Run Code
Some important points about Huge Pointer are as follows:-
- A huge pointer is a pointer that may point to any section in the memory. A huge pointer is 4 bytes or 32 bits in size and can access up to 64K of memory.
- Without suffering from segment work round, the huge pointer can be increased.
You can also read about the dynamic arrays in c
Difference between Far Pointer and Near Pointer
Here are the differences between far and near with respect to:
1. Memory Access:
- Near pointers access memory within the same segment as the data or code.
- Far pointers can access memory across different segments, useful for accessing data beyond the 64KB limit in segmented memory models.
2. Size:
- Near pointers are typically 16-bit on most platforms, allowing direct access to limited memory.
- Far pointers are larger, often 32-bit or more, accommodating segmented memory addressing.
3. Segmentation:
- Near pointers are limited to accessing memory within the same segment, restricting access to nearby memory.
- Far pointers facilitate accessing memory in different segments, extending the range of accessible memory.
Difference between Far Pointer and Huge Pointer
Here are the differences between far and huge with respect to:
1. Scope:
- Far pointers extend the addressable range beyond the default near pointers, accessing memory across different segments.
- Huge pointers are a workaround used in some older compilers to manage memory models, typically equivalent to far pointers.
2. Implementation:
- Far pointers are a standard feature in segmented memory models, supported by compilers for accessing data beyond the 64KB segment limit.
- Huge pointers are a non-standard extension or workaround implemented by some compilers, offering similar capabilities as far pointers.
3. Usage:
- Far pointers are commonly used in segmented memory models, especially in older programming environments like MS-DOS.
- Huge pointers are less common and were primarily used in specific contexts where far pointers alone couldn't address extensive memory requirements, often in older or specialized systems.
Frequently Asked Questions
How big is the far pointer?
Far pointers are typically 32-bit or larger, accommodating segmented memory addressing.
What is a huge pointer?
Huge pointers have a 32-bit size pointer that may point to any section in the memory.
What is a near pointer?
A near-pointer is used to hold 16-bit addresses within the current segment. It is two bytes in size.
What is a far pointer and where is it used?
A far pointer accesses memory across segments, useful in segmented memory models like those in older environments such as MS-DOS programming.
Conclusion
In this article, we have extensively discussed the near, far, and huge pointer, their syntax, and program.
We hope this blog has helped you enhance your knowledge regarding the near, far, and huge pointers in C language. Some official documentation on C programming language that can help you improve your understanding is C documentation.