Prerequisite : Pointers in C and C++
We already know that a pointer points to a location in memory and thus used to store address of variables. So, when we define a pointer to pointer. The first pointer is used to store the address of second pointer. That is why they are also known as double pointers.
How to declare a pointer to pointer in C?
Declaring Pointer to Pointer is similar to declaring pointer in C. The difference is we have to place an additional ‘*’ before the name of pointer.
int **ptr; // declaring double pointers
Below diagram explains the concept of Double Pointers:
The above diagram shows the memory representation of a pointer to pointer. The first pointer ptr1 stores the address of the second pointer ptr2 and the second pointer ptr2 stores the address of the variable.
Let us understand this more clearly with the help of below program:
Value of var = 789 Value of var using single pointer = 789 Value of var using double pointer = 789
Function Pointer in C
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.