C++ Pointer To Pointer (Double Pointer)

Last Updated : 18 Jun, 2026

A Double Pointer (Pointer to Pointer) is a pointer that stores the address of another pointer. It provides an additional level of indirection for accessing data.

  • The first pointer stores the address of a variable.
  • The second pointer stores the address of the first pointer.
DoublePointer1
C++ Pointer To Pointer

Declaring a Pointer to Pointer

A pointer to pointer is declared by placing an additional * before the pointer name. The first * represents a pointer, while the second * indicates that the pointer stores the address of another pointer.

Syntax

data_type **pointer_name = &pointer_variable;

Here,

  • data_type specifies the type of data being pointed to.
  • ** indicates a pointer to another pointer.
  • pointer_name is the name of the double pointer.
  • pointer_variable is an existing pointer whose address is stored.

Example: Declaring and Using a Double Pointer

C++
#include <bits/stdc++.h>
using namespace std;

// Driver code
int main()
{
  int variable = 169;
  
  // Pointer to store the address 
  // of variable
  int* pointer1;

  // double pointer to store the 
  // address of pointer1
  int** pointer2;

  // Storing address of variable 
  // in pointer1
  pointer1 = &variable;

  // Storing address of pointer1 
  // in pointer2
  pointer2 = &pointer1;

  // Displaying the value of variable 
  // with using both single and double 
  // pointers.
  cout << "Value of variable :- " << 
           variable << "\n";
  cout << "Value of variable using single pointer :- " << 
           *pointer1 << "\n";
  cout << "Value of variable using double pointer :- " << 
           **pointer2 << "\n";
  return 0;
}

Output
Value of variable :- 169
Value of variable using single pointer :- 169
Value of variable using double pointer :- 169

Explanation: pointer1 stores the address of variable, while pointer2 stores the address of pointer1. Dereferencing pointer2 once gives pointer1, and dereferencing it a second time retrieves the value stored in variable.

Pointer to Pointer Representation

The following diagram illustrates the relationship between a variable, a pointer, and a pointer to pointer.

DoublePointer

Working of a Double Pointer

A double pointer introduces two levels of indirection.

Example: How does Double Pointer works?
  • pointer1 stores the address of the variable.
  • pointer2 stores the address of pointer1.
  • *pointer2 gives pointer1.
  • **pointer2 gives the value stored in the original variable.

Size of a Double Pointer

A double pointer occupies the same amount of memory as a normal pointer because both store only memory addresses. The size depends on the system architecture rather than the pointer type.

  • On most 64-bit systems, pointers occupy 8 bytes.
  • On most 32-bit systems, pointers occupy 4 bytes.
C++
#include <bits/stdc++.h>
using namespace std;

// Driver code
int main()
{
  int val = 169;
  int* ptr = &val;
  int** double_ptr = &ptr;

  cout << " Size of normal Pointer: " << 
            sizeof(ptr) << "\n";
  cout << " Size of double Pointer: " << 
            sizeof(double_ptr) << "\n";
  return 0;
}

Output
 Size of normal Pointer: 8
 Size of double Pointer: 8

Explanation: Both ptr and doublePtr store memory addresses, so they occupy the same amount of memory. The actual size depends on the architecture of the system.

Note: The size of a pointer depends on the system architecture. It is typically 8 bytes on 64-bit systems and **4 bytes on 32-bit systems.

Applications of Double Pointer

Double pointers are commonly used in the following situations:

  • Modifying pointers inside functions by passing a pointer to a pointer.
  • Dynamic memory allocation where the allocated pointer needs to be updated.
  • Implementing multidimensional dynamic arrays.
  • Building complex data structures such as linked lists, trees, and graphs.
Comment