Prerequisite : Pointers in C and C++
We already know that a pointer points to a location in memory and thus used to store the address of variables. So, when we define a pointer to 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.
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 variable and the second pointer ptr2 stores the address of the first pointer.
Let us understand this more clearly with the help of the below program:
Value of var = 789 Value of var using single pointer = 789 Value of var using double pointer = 789
Function Pointer in C
This article is contributed by Harsh Agarwal. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Delete multiple occurrences of key in Linked list using double pointer
- Pointer to an Array | Array Pointer
- What is a Pointer to a Null pointer
- What is the difference between single quoted and double quoted declaration of char array?
- Double forking to prevent Zombie process
- Difference between float and double in C/C++
- C program to print a string without any quote (singe or double) in the program
- Modulus of two float or double numbers
- C/C++ program to find the size of int, float, double and char
- How to declare a pointer to a function?
- Pointer vs Array in C
- 'this' pointer in C++
- Multidimensional Pointer Arithmetic in C/C++
- How to write C functions that modify head pointer of a Linked List?
- Function Pointer in C
- Opaque Pointer
- Passing by pointer Vs Passing by Reference in C++
- void pointer in C / C++
- NULL pointer in C
- C | Pointer Basics | Question 1