Home > Backend Development > C++ > Explain Near, Far and Huge pointers in C language

Explain Near, Far and Huge pointers in C language

WBOY
Release: 2023-09-14 15:13:02
forward
1538 people have browsed it

Explain Near, Far and Huge pointers in C language

Based on the memory model and segment, pointers are divided into three types -

  • Near pointer
  • Far pointer
  • Large pointer

Near pointer

  • 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.

Grammar

The syntax is as follows-

<data type> near <pointer definition>
<data type> near <function definition>
Copy after login

The following statement declares the near pointer of variable s

char near *string;
Copy after login

Program

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;
}
Copy after login

Output

The output is as follows-

2
Copy after login

Far pointer

  • It is a pointer, which stores different pointers offset and segment address.

  • < li>

    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.

Grammar

The syntax is as follows-

<data type> far <pointer definition>
<data type> far <function definition>
Copy after login

The following statement declares the far pointer of variable s

char far *s;
Copy after login

Program

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;
}
Copy after login

Output

The output is as follows -

4
Copy after login

Large pointer

  • 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.

Procedure

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;
}
Copy after login

Output

The output is as follows -

4 4 1
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template