GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • C++ Tutorial
  • Interview Questions
  • Examples
  • Quizzes
  • Projects
  • Cheatsheet
  • OOP
  • Exception Handling
  • STL
  • DSA C++
  • Introduction2 min read
  • Data Types4 min read
  • Variables4 min read
  • Operators9 min read

This view

  • Original page
  • New address

GeezerVison is showing www.geeksforgeeks.org — C++ Pointer To Pointer (Double Pointer) - GeeksforGeeks

geeksforgeeks
search icon
  • Courses
  • Tutorials
  • Interview Prep
  • C++ Tutorial
  • Interview Questions
  • Examples
  • Quizzes
  • Projects
  • Cheatsheet
  • OOP
  • Exception Handling
  • STL
  • DSA C++

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

Explore

    C++ Basics
    • Introduction2 min read
    • Data Types4 min read
    • Variables4 min read
    • Operators9 min read
    • Basic Input / Output2 min read
    • Control Flow Statements15+ min read
    • Loops7 min read
    • Functions5 min read
    • Arrays5 min read
    Core Concepts
    • Pointers and References4 min read
    • new and delete Operators5 min read
    • Templates in C++7 min read
    • Struct Union Enum3 min read
    • Exception Handling5 min read
    • File Handling9 min read
    • Multithreading6 min read
    • Namespace5 min read
    OOP
    • OOP Concepts10 min read
    • Inheritance6 min read
    • Polymorphism5 min read
    • Encapsulation3 min read
    • Abstraction4 min read
    Standard Template Library(STL)
    • STL3 min read
    • Container Library3 min read
    • Iterators10 min read
    • Algorithm Library3 min read
    Practice & Problems
    • Interview Questions15+ min read
    • Programming Examples4 min read
    Courses
    • Placement 360 Course2 min read
    • DSA and System Design Course2 min read
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.