Say you have the following code:
int *p;
int **p2;
int k;
We can then initialize k
and make p
point to it. Afterwards we can let p2
point to the pointer p
:
k = 10;
p = &i;
p2 = &p;
We will now dereference p2
twice to see what the value the pointer p2
points to are pointing at (using simple C++):
#include <iostream>
...
std::cout << "What is k? Answer: " << **p2;
--> What is k? Answer: 10
It is also possible to change the value of k
by dereferencing it
**p2 = 19;
std::cout << "What is k now? Answer: " << **p2;
--> What is k now? Answer: 19
I hope this can help new programmers get an idea of how pointers to pointers can dereferenced. If triple (or more) pointers are wanted, simply dereference more levels
int ***p3 = &p2;
***p3 = 60;
std::cout << "What is k now? Answer: " << ***p3;
--> What is k now? Answer: 60
More information about what dereferencing really means can be found in
What does "dereferencing" a pointer mean?