What is near pointer ?




In TURBO C there are three types of pointers. TURBO C works under DOS operating system which is based on 8085 microprocessor.
1. near pointer
2. far pointer
3. huge pointer

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 help keyword near, we can make any pointer as near pointer.
Example:
void main(){
int x=25;
int near* ptr;
ptr=&x;
printf(“%d”,sizeof ptr);
}
Output: 2
Near pointer only hold 16 bit offset address. Offset address varies from 0000 to FFFF (in hexadecimal).
Note: In printf statement to print the offset address in hexadecimal, %p is used.
Consider following c program:
void main(){
int near * ptr=( int *)0XFFFF;
ptr++;
ptr++;
printf(“%p”,ptr);
}
Output: 0003
Explanation: When we increment or decrement the offset address from maximum and minimum value respectively then it repeats the same value in cyclic order. This property is known as cyclic nature of offset address.
Cyclic property of offset address.
If you increment the near pointer variable then move clockwise direction. If you decrement the near pointer then move anti clockwise direction.



What is default type of pointer in C?
Answer: It depends upon memory model.

No comments: