A pointer to pointer in C is a pointer variable that stores the address of another pointer. Since a normal pointer stores the address of a normal variable, a pointer to pointer adds one more level of indirection. This idea sounds complex at first, but it becomes manageable once you build it step by step.
Pointer to pointer is useful in multi-level memory access, dynamic memory handling, arrays of pointers, and functions that need to modify a pointer itself. In this article, we will understand pointer to pointer in C, its syntax, memory structure, dereferencing rules, common examples, practical uses, and common mistakes.
What is Pointer to Pointer in C?
A pointer to pointer in C is a pointer that stores the address of another pointer. If a variable stores a value, and a pointer stores the address of that variable, then a pointer to pointer stores the address of that pointer.
This creates a chain like this:
- normal variable stores a value
- pointer stores the address of that variable
- pointer to pointer stores the address of that pointer
A pointer to pointer does not point directly to the final data. It points to another pointer first.
Syntax of Pointer to Pointer in C
The syntax uses two asterisks because there are two levels of indirection.
data_type **pointer_name;Example:
int **pptr;This means pptr is a pointer that can store the address of an int * pointer.
| Declaration | Meaning |
|---|---|
int x; | Normal integer variable |
int *ptr; | Pointer to integer |
int **pptr; | Pointer to pointer to integer |
Example of Pointer to Pointer in C
The following example shows how the chain works in memory.
#include <stdio.h>
int main(void)
{
int x = 10;
int *ptr = &x;
int **pptr = &ptr;
printf("Value of x = %d\n", x);
printf("Value using ptr = %d\n", *ptr);
printf("Value using pptr = %d\n", **pptr);
return 0;
}Here:
xstores the value10ptrstores the address ofxpptrstores the address ofptr*ptrgives the value ofx**pptralso gives the value ofx
How Dereferencing Works with Pointer to Pointer
Dereferencing depends on how many levels of pointers are involved.
| Expression | Meaning |
|---|---|
ptr | Address of the original variable |
*ptr | Value of the original variable |
pptr | Address of pointer ptr |
*pptr | Value stored in pptr, which is the address of x |
**pptr | Final value of x |
This is why each * removes one level of indirection.
Memory View of Pointer to Pointer in C
You can think of the memory chain like this:
xcontains the actual integer valueptrcontains the address ofxpptrcontains the address ofptr
So when you use **pptr, you first reach ptr, and then through ptr you reach x.
Changing a Value Using Pointer to Pointer in C
A pointer to pointer can also be used to modify the original value.
#include <stdio.h>
int main(void)
{
int x = 5;
int *ptr = &x;
int **pptr = &ptr;
**pptr = 50;
printf("%d\n", x);
return 0;
}After assigning **pptr = 50;, the value of x becomes 50.
Pointer to Pointer and Functions in C
Pointer to pointer becomes especially useful when a function must modify a pointer itself. If you pass only a normal pointer, the function receives a copy of that pointer. But if you pass the address of the pointer, the function can update the original pointer.
#include <stdio.h>
void setPointer(int **pp, int *target)
{
*pp = target;
}
int main(void)
{
int x = 10;
int *ptr = NULL;
setPointer(&ptr, &x);
printf("%d\n", *ptr);
return 0;
}This pattern is common in dynamic memory allocation and multi-level data handling.
Where Pointer to Pointer is Used in C
- when a function needs to change a pointer
- in dynamic memory allocation helpers
- for arrays of strings
- in 2D dynamic memory layouts
- in advanced data structures
- in command line argument handling concepts such as
char **argv
This is why pointer to pointer is not just theory. It appears in many practical C programs.
Pointer to Pointer vs Normal Pointer in C
| Point | Normal pointer | Pointer to pointer |
|---|---|---|
| Stores | Address of a normal variable | Address of another pointer |
| Dereference level | One * | Two * operators |
| Typical use | Accessing data by address | Accessing or modifying another pointer |
Advantages of Pointer to Pointer in C
- allows modification of pointer values inside functions
- supports multi-level memory structures
- useful for dynamic memory management patterns
- important for arrays of pointers and string lists
- helps build more advanced data structures
Common Mistakes with Pointer to Pointer in C
- confusing
*ptrand**pptr - using the wrong pointer type
- forgetting how many dereference levels are needed
- dereferencing an invalid pointer chain
- not understanding which address is stored at each level
| Mistake | Problem | Better understanding |
|---|---|---|
Using one * instead of two | Gets the pointer value, not final data | Each * removes one level of indirection |
| Wrong declaration type | Type mismatch and logic errors | Match the declaration to the pointer level exactly |
| Dereferencing invalid chain | Can crash the program | Ensure every level points to valid memory |
Best Practices for Learning Pointer to Pointer in C
- Start with one variable, one pointer, and one pointer to pointer.
- Track the chain clearly on paper if needed.
- Practice with both value access and pointer-changing examples.
- Use clear variable names such as
ptrandpptrwhile learning. - Move slowly and verify each level of dereferencing.
FAQs
What is pointer to pointer in C?
Pointer to pointer in C is a pointer that stores the address of another pointer.
How do you declare a pointer to pointer in C?
You declare it using two asterisks, such as int **pptr;.
What does **pptr mean in C?
**pptr means dereference the pointer to pointer twice to reach the final stored value.
Why is pointer to pointer used in C?
It is used when a function must modify a pointer, in dynamic memory handling, arrays of strings, and other multi-level memory tasks.
Can pointer to pointer change the original variable value?
Yes. By using **pptr, you can access and modify the original variable value.
Is pointer to pointer difficult in C?
It can feel difficult initially, but it becomes easier when you understand each level of address storage step by step.