Application of Double Pointers in C

Following are the main uses of pointer to pointers in C:

  • They are used in the dynamic memory allocation of multidimensional arrays.
  • They can be used to store multilevel data such as the text document paragraph, sentences, and word semantics.
  • They are used in data structures to directly manipulate the address of the nodes without copying.
  • They can be used as function arguments to manipulate the address stored in the local pointer.

C – Pointer to Pointer (Double Pointer)

Prerequisite: Pointers in C

The pointer to a pointer in C is used when we want to store the address of another pointer. The first pointer is used to store the address of the variable. And the second pointer is used to store the address of the first pointer. That is why they are also known as double-pointers. We can use a pointer to a pointer to change the values of normal pointers or create a variable-sized 2-D array. A double pointer occupies the same amount of space in the memory stack as a normal pointer.

 

Similar Reads

Declaration of Pointer to a Pointer in C

Declaring Pointer to Pointer is similar to declaring a pointer in C. The difference is we have to place an additional ‘*’ before the name of the pointer....

Example of Double Pointer in C

C // C program to demonstrate pointer to pointer #include   int main() {     int var = 789;       // pointer for var     int* ptr2;       // double pointer for ptr2     int** ptr1;       // storing address of var in ptr2     ptr2 = &var;       // Storing address of ptr2 in ptr1     ptr1 = &ptr2;       // Displaying value of var using     // both single and double pointers     printf("Value of var = %d\n", var);     printf("Value of var using single pointer = %d\n", *ptr2);     printf("Value of var using double pointer = %d\n", **ptr1);       return 0; }...

How Double Pointer Works?

...

Size of Pointer to Pointer in C

...

Application of Double Pointers in C

In the C programming language, a double pointer behaves similarly to a normal pointer in C. So, the size of the double-pointer variable is always equal to the normal pointers. We can verify this using the below C Program....

Multilevel Pointers in C

...