Pointers in C programming language.

Asked By 20 points N/A Posted on -
qa-featured

What are far pointers, near pointers, and huge pointers in the C programming language? What can they be used for? Thanks.

SHARE
Best Answer by Sharath Reddy
Answered By 0 points N/A #152054

Pointers in C programming language.

qa-featured

Hello,

Near pointer is The pointer which cans points only 64 KB data segment or segment number 8 . That is near pointer cannot access beyond the data segment like graphics video memory, text video memory etc. Size of near pointer is 2 byte.

The far pointer is the pointer which can point or access whole the residence memory of RAMS i.e. which can access all 16 segments, Size of far pointer is 4 byte or 32 bit.

The pointer which can point or access whole the residence memory of RAM i.e. which can access all the 16 segments, Size of huge pointer is 4 byte or 32 bit.

Best Answer
Best Answer
Answered By 590495 points N/A #152055

Pointers in C programming language.

qa-featured

Since you want to know all about the different types of pointers in C language, let’s define first the meaning of a pointer. A pointer is a variable where its content is the address of another variable. An example of this is the exact address of the memory location.

Like any other constant or variable, you need to declare a pointer first before you can actually use it to store variable address. The correct syntax in declaring a pointer is:

  • type *var-name;

“type” is the base type of the pointer and it should be a valid C data type. “var-name” is the pointer variable’s name. Below are examples of valid pointer declaration:

  • int    *ip;    /* pointer to an integer */
  • double *dp;    /* pointer to a double */
  • char   *ch     /* pointer to a character */

A far pointer is the type of pointer that can access as a whole the entire memory segments of the memory, like for example all 16 segments of the memory as what is described in the image below.

Here is an example of a far pointer that will have an output of 4.

#include<stdio.h>
 
int main(){
 
int x=10;
int far *ptr;
 
ptr=&x;
printf("%d",sizeof ptr);

return 0;
}

The near pointer is the type of pointer that can only point 64kb data segment. See the image below.

Here is an example of near pointer that will have an output of 2.

#include<stdio.h>
 
int main(){
 
int x=25;
int near* ptr;
 
ptr=&x;
printf(“%d”,sizeof ptr);

return 0;

}

The huge pointer is the type of pointer that can point to the entire 16 segments of the memory. This is similar to the far pointer. See the image below.

Here is an example of huge pointer that will have 4 4 1 as the output.

#include<stdio.h>
int main(){
char huge * far *p;
printf("%d %d %d",sizeof(p),sizeof(*p),sizeof(**p));

return 0;
}

So, to sum it all, the three types of pointers are:

  • Near pointer
  • Far pointer, and
  • Huge pointer

Related Questions