Types of Pointers
There are eight different types of pointers which are as follows −

Null pointer

Void pointer

Wild pointer

Dangling pointer

Complex pointer

Near pointer

Far pointer

Huge pointer

--------

Null :- What Is a Null Value?
In a database, zero is a value. The value null means that no value exists.
When used as a value, null is not a memory location.
Only pointers hold memory locations. Without a null character, 
a string would not correctly terminate, which would cause problems.

What Is a Null Pointer?
The C and C++ programming, a pointer is a variable that holds a memory location.
The null pointer is a pointer that intentionally points to nothing.
If you don't have an address to assign to a pointer, you can use null.

The null value avoids memory leaks and crashes in applications that contain
pointers. An example of a null pointer in C is:

#include
int main()
{
  int *ptr = NULL;
  printf("The value of ptr is %u",ptr);
  return 0;
}

Output :- Pointer value is 0

Note: In C, the null macro may have the type void* but this is not allowed in C++.

------

Void pointer

The void pointer in C is a pointer that is not associated with any data types.
It points to some data location in the storage. 
This means that it points to the address of variables. 
It is also called the general purpose pointer.
In C, malloc() and calloc() functions return void * or generic pointers.
These are some old concepts used in 16 bit intel architectures in the days
of MS DOS, not much useful anymore.

--------

Near pointer is used to store 16 bit addresses means within current segment on
a 16 bit machine. The limitation is that we can only access 64kb of data at a time.

A far pointer is typically 32 bit that can access memory outside current segment.
To use this, compiler allocates a segment register to store segment address,
then another register to store offset within current segment.

Like far pointer, huge pointer is also typically 32 bit and can access outside segment. In case of far pointers, a segment is fixed. In far pointer, the segment part cannot be modified, but in Huge it can be

#include<stdio.h>  
  
    int main()  
      {  
          int x=25;  
          int near* ptr; //output =2 as 16bytes//if fer = 4 = huge//
          ptr=&x;  
          printf("%d",sizeof ptr);  
          return 0;  
      }
      
------------------------------------------------------------------------------------

A wild pointer is a pointer that has not been initialized to a valid memory address.
Using a wild pointer can lead to undefined behavior in a program, including 
crashes and data corruption.

Here is an example of a wild pointer in C:

Copy code
int *ptr;  // Declare a pointer to an integer

*ptr = 5;  // Dereference the wild pointer
           // This can cause a crash or other unexpected behavior
To avoid using a wild pointer, you should make sure to initialize the pointer 
to a valid memory address before using it. For example:

Copy code
int x = 10;
int *ptr = &x;  // Initialize ptr to the address of x

*ptr = 5;      // Now it is safe to dereference ptr

------------------------------------------------------------------------------------

A complex pointer is a pointer that points to another pointer. It can be used 
to store the address of a pointer variable. For example:

int a = 5;
int *ptr1 = &a; // ptr1 is a pointer that stores the address of variable a
int **ptr2 = &ptr1; // ptr2 is a complex pointer that stores the address of ptr1

Here, ptr2 is a complex pointer that points to the address of ptr1, which is
a pointer that points to the address of a, which is an integer variable. You 
can use a complex pointer to indirectly access the value of a as follows:

int val = **ptr2; // val is assigned the value of a (5)

You can also use a complex pointer to modify the value of a indirectly:

**ptr2 = 10; // Sets the value of a to 10

I hope this helps! Let me know if you have any questions.

------------------------------------------------------------------------------------

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: