Types of pointers
NULL pointer
if a pointer does not point to any variable, it can be initialized to NULL to indicate that it does not hold any valid address.
Example: int *ptr=NULL;
Dangling pointer
A pointer which holds the address of a variable which no longer exists, is a dangling pointer. Example:
void main()
{ int *ptr;
{ int num=10;
ptr=#
}
//num is destroyed
//ptr is still holds address of num so it is dangling pointer.
}
Generic/void pointer
A pointer which points to ‘void’ data type is called a generic pointer. In ‘C’, void represents the absence of type, so void pointers are pointers that point to a value that has no type. This allows void pointers to point to any data type.
Example:
void *ptr;
(int *)ptr=&n;
Uninitialized/wild pointer
A pointer which has not been assigned any address till it is first used in a program is called an uninitialized or wild pointer. It contains some garbage value.
Near pointer: A near pointer is a 16 bit pointer (2 byte) to an object contained in the current segment, be it code segment, data segment, stack segment, or extra segment. Hence it can access only 216memory locations i.e. 65536 bytes(64KB).
Near pointer
A near pointer is a 16 bit pointer (2 byte) to an object contained in the current segment, be it code segment, data segment, stack segment, or extra segment. Hence it can access only 216memory locations i.e. 65536 bytes(64KB).
Example: int near *ptr;
Far pointer
A far pointer is 4 bytes (32 bits) and can access memory outside the current segment. A far pointer is a 32 bit pointer to an object anywhere in memory. Example: int far *ptr;
Huge pointer
Like the far pointer, huge pointer is also typically 32 bits and can access memory outside the current segment. Huge pointer can access multiple segments of memory.
Example: int huge *ptr;
Also Read
- Static and Dynamic Memory Allocation
- Memory Leak and Dangling Pointer
- Memory Allocation for 2D Array
- Dynamic Memory Allocation
- Pointer Constant and Constant Pointer
- Pointer Declarations and their Meanings
- Functions and Pointers
- Initializing Pointer to Pointer
- Pointer to Pointer Multiple Indirection
- Relationship between Array and Pointer
- Pointer to Array
- Pointer Arithmetic
- Illustrate Basic Pointer Use
- Using Pointer
- Intializing Pointer
- Declaring Pointer
- Application of Pointers
- Value Model VS Reference Model
- What is Pointer
Comments
Post a Comment
Please give us feedback through comments