100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
C++

Pointer to Pointer in C++

Learn how a pointer can itself store the address of another pointer, requiring double dereferencing to reach the underlying value.

PointersIntermediate7 min readJul 7, 2026
Analogies

1. Intro

A pointer to pointer (also called a double pointer) is a pointer variable that stores the address of another pointer, rather than the address of an ordinary variable. Since a pointer variable itself lives at some address in memory, another pointer can point to it, creating a chain of indirection.

🏏

Cricket analogy: A team manager holds the phone number of the captain, who in turn holds the batting order — the manager doesn't know the batting order directly but reaches it through the captain, just as a double pointer reaches a value through another pointer.

2. Syntax

cpp
int** pp;             // declares a pointer to a pointer to int
int x = 5;
int* p = &x;           // p points to x
pp = &p;                // pp points to p
**pp;                   // dereference twice to reach x's value

3. Explanation

Declaring int** pp; creates a variable pp whose job is to hold the address of an int* pointer. To get from pp all the way down to the original int value, you need to dereference twice: *pp gives you back the pointer p (an int*, i.e. an address), and **pp gives you the actual int value that p points to. Each * "peels off" one level of indirection. Pointer-to-pointer is commonly used for dynamically allocated 2D arrays, for functions that need to modify a caller's pointer (not just the value it points to), and for arrays of strings/pointers such as char** argv in main.

🏏

Cricket analogy: Declaring int** pp is like a scorer's master sheet that references a specific over sheet (*pp gets you the over sheet reference), and reading that over sheet (**pp) finally gives you Rohit Sharma's actual runs scored.

4. Example

cpp
#include <iostream>
using namespace std;

int main() {
    int x = 5;
    int* p = &x;      // p points to x
    int** pp = &p;     // pp points to p

    cout << "x    = " << x << endl;
    cout << "*p   = " << *p << endl;
    cout << "**pp = " << **pp << endl;

    **pp = 99;   // modifies x through two levels of indirection
    cout << "After **pp = 99, x = " << x << endl;

    return 0;
}

5. Output

text
x    = 5
*p   = 5
**pp = 5
After **pp = 99, x = 99

6. Key Takeaways

  • A pointer to pointer stores the address of another pointer, declared as int** pp;.
  • *pp gives the pointer it stores (p); **pp dereferences twice to reach the original value.
  • Each level of * peels off one layer of indirection.
  • Double pointers are used for dynamic 2D arrays, modifying a caller's pointer, and arrays of pointers (e.g. char** argv).

Practice what you learned

Was this page helpful?

Topics covered

#CStudyNotes#Programming#PointerToPointerInC#Pointer#Syntax#Explanation#Example#StudyNotes#SkillVeris#ExamPrep