Let's assume an 8 bit computer with 8 bit addresses (and thus only 256 bytes of memory). This is part of that memory (the numbers at the top are the addresses):

  54   55   56   57   58   59   60   61   62   63   64   65   66   67   68   69
+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
|    | 58 |    |    | 63 |    | 55 |    |    | h  | e  | l  | l  | o  | \0 |    |
+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+

What you can see here, is that at address 63 the string "hello" starts. So in this case, if this is the only occurrence of "hello" in memory then,

const char *c = "hello";

... defines c to be a pointer to the (read-only) string "hello", and thus contains the value 63. c must itself be stored somewhere: in the example above at location 58. Of course we can not only point to characters, but also to other pointers. E.g.:

const char **cp = &c;

Now cp points to c, that is, it contains the address of c (which is 58). We can go even further. Consider:

const char ***cpp = &cp;

Now cpp stores the address of cp. So it has value 55 (based on the example above), and you guessed it: it is itself stored at address 60.


As to why one uses pointers to pointers:

  • The name of an array usually yields the address of its first element. So if the array contains elements of type t, a reference to the array has type t *. Now consider an array of arrays of type t: naturally a reference to this 2D array will have type (t *)* = t **, and is hence a pointer to a pointer.
  • Even though an array of strings sounds one-dimensional, it is in fact two-dimensional, since strings are character arrays. Hence: char **.
  • A function f will need to accept an argument of type t ** if it is to alter a variable of type t *.
  • Many other reasons that are too numerous to list here.
Answer from Stephan202 on Stack Overflow
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ cprogramming โ€บ c_pointer_to_pointer.htm
Pointer to Pointer (Double Pointer) in C
The declaration of a pointer to pointer (double pointer) is similar to the declaration of a pointer, the only difference is that you need to use an additional asterisk (*) before the pointer variable name. For example, the following declaration declares a "pointer to a pointer" of type int
๐ŸŒ
Log2Base2
log2base2.com โ€บ C โ€บ pointer โ€บ pointer-to-pointer-in-c.html
Pointer to pointer in c with example
/* * Program : Pointer to Pointer * Language : C */ #include<stdio.h> int main() { int a = 10; int *ptr = &a; //ptr references a int **dptr = &ptr; //dptr references ptr printf("Address of a = %p\n",&a); printf("ptr is pointing to the address = %p\n",ptr); printf("dptr is pointing to the address = %p\n",dptr); printf("Value of a = %d\n",a); printf("*ptr = %d\n",*ptr); printf("**dptr = %d\n",**dptr); return 0; }
Discussions

How do pointer-to-pointers work in C? (and when might you use them?) - Stack Overflow
A pointer to pointer is not a special case of something, so I don't understand what you don't understand about void**. ... for 2D arrays the best example is the command line args "prog arg1 arg2" is stored char**argv. More on stackoverflow.com
๐ŸŒ stackoverflow.com
What's the use of pointers-to-pointers?
Well a pointer is also data, so it's useful everywhere where having a pointer to data is useful. One usecase I find kinda neat is for linked list algorithms. See https://github.com/mkirchner/linked-list-good-taste More on reddit.com
๐ŸŒ r/C_Programming
32
47
May 11, 2023
When to use Pointer-to-Pointer in C++? - Stack Overflow
I was wondering when we use Pointer to Pointer in C++ and why we need to point to a pointer? I know that when we point to a pointer it means we are saving the memory address of a variable into the memory but I don't know why we need it? Also I have seen some examples that always the use ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
c - Why use double indirection? or Why use pointers to pointers? - Stack Overflow
When should a double indirection be used in C? Can anyone explain with a example? What I know is that a double indirection is a pointer to a pointer. Why would I need a pointer to a pointer? More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ c language โ€บ c-pointer-to-pointer-double-pointer
C - Pointer to Pointer (Double Pointer) - GeeksforGeeks
Examples ยท Quizzes ยท Projects ยท Cheatsheet ยท File Handling ยท Multithreading ยท Memory Layout ยท DSA in C ยท C++ Last Updated : 18 Jul, 2026 ยท A double pointer in C is a pointer that stores the address of another pointer. It is also known as a pointer to a pointer because it points to another pointer instead of directly pointing to a variable.
Published: July 18, 2026
Top answer
1 of 14
416

Let's assume an 8 bit computer with 8 bit addresses (and thus only 256 bytes of memory). This is part of that memory (the numbers at the top are the addresses):

  54   55   56   57   58   59   60   61   62   63   64   65   66   67   68   69
+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
|    | 58 |    |    | 63 |    | 55 |    |    | h  | e  | l  | l  | o  | \0 |    |
+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+

What you can see here, is that at address 63 the string "hello" starts. So in this case, if this is the only occurrence of "hello" in memory then,

const char *c = "hello";

... defines c to be a pointer to the (read-only) string "hello", and thus contains the value 63. c must itself be stored somewhere: in the example above at location 58. Of course we can not only point to characters, but also to other pointers. E.g.:

const char **cp = &c;

Now cp points to c, that is, it contains the address of c (which is 58). We can go even further. Consider:

const char ***cpp = &cp;

Now cpp stores the address of cp. So it has value 55 (based on the example above), and you guessed it: it is itself stored at address 60.


As to why one uses pointers to pointers:

  • The name of an array usually yields the address of its first element. So if the array contains elements of type t, a reference to the array has type t *. Now consider an array of arrays of type t: naturally a reference to this 2D array will have type (t *)* = t **, and is hence a pointer to a pointer.
  • Even though an array of strings sounds one-dimensional, it is in fact two-dimensional, since strings are character arrays. Hence: char **.
  • A function f will need to accept an argument of type t ** if it is to alter a variable of type t *.
  • Many other reasons that are too numerous to list here.
2 of 14
55

How do pointers to pointers work in C?

First a pointer is a variable, like any other variable, but that holds the address of a variable.

A pointer to a pointer is a variable, like any other variable, but that holds the address of a variable. That variable just happens to be a pointer.

When would you use them?

You can use them when you need to return a pointer to some memory on the heap, but not using the return value.

Example:

int getValueOf5(int *p)
{
  *p = 5;
  return 1;//success
}

int get1024HeapMemory(int **p)
{
  *p = malloc(1024);
  if(*p == 0)
    return -1;//error
  else 
    return 0;//success
}

And you call it like this:

int x;
getValueOf5(&x);//I want to fill the int varaible, so I pass it's address in
//At this point x holds 5

int *p;    
get1024HeapMemory(&p);//I want to fill the int* variable, so I pass it's address in
//At this point p holds a memory address where 1024 bytes of memory is allocated on the heap

There are other uses too, like the main() argument of every C program has a pointer to a pointer for argv, where each element holds an array of chars that are the command line options. You must be careful though when you use pointers of pointers to point to 2 dimensional arrays, it's better to use a pointer to a 2 dimensional array instead.

Why it's dangerous?

void test()
{
  double **a;
  int i1 = sizeof(a[0]);//i1 == 4 == sizeof(double*)

  double matrix[ROWS][COLUMNS];
  int i2 = sizeof(matrix[0]);//i2 == 240 == COLUMNS * sizeof(double)
}

Here is an example of a pointer to a 2 dimensional array done properly:

int (*myPointerTo2DimArray)[ROWS][COLUMNS]

You can't use a pointer to a 2 dimensional array though if you want to support a variable number of elements for the ROWS and COLUMNS. But when you know before hand you would use a 2 dimensional array.

๐ŸŒ
W3Schools
w3schools.com โ€บ cpp โ€บ cpp_pointers.asp
C++ Pointers
C++ Examples C++ Real-Life Examples C++ Compiler C++ Exercises C++ Quiz C++ Code Challenges C++ Practice Problems C++ Syllabus C++ Study Plan ... You learned from the previous chapter, that we can get the memory address of a variable by using the & operator: string food = "Pizza"; // A food variable of type string cout << food; // Outputs the value of food (Pizza) cout << &food; // Outputs the memory address of food (0x6dfed4) Try it Yourself ยป ยท A pointer however, is a variable that stores the memory address as its value.
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ c โ€“ pointer to pointer (double pointer)
C โ€“ Pointer to Pointer (Double Pointer) - Scaler Topics
October 10, 2023 - We declare a double pointer ptr2 and make it point to the address of ptr1. We then demonstrate how to access and modify the value of value using all three levels of indirection: directly using value, through ptr1, and through ptr2. Finally, we update the value through ptr2 and verify the change.
Find elsewhere
๐ŸŒ
Dot Net Tutorials
dotnettutorials.net โ€บ home โ€บ pointer to pointer in c
Pointer to Pointer in C Language with Examples - Dot Net Tutorials
November 16, 2023 - Consider a regular pointer: int x = 10; int *p = &x; // โ€˜pโ€™ is a pointer to โ€˜xโ€™ ยท Here, p is a pointer that holds the address of x.
๐ŸŒ
W3Schools
w3schools.com โ€บ c โ€บ c_pointers.php
C Pointers
Create a pointer variable with the name ptr, that points to an int variable (myAge). Note that the type of the pointer has to match the type of the variable you're working with (int in our example).
๐ŸŒ
Reddit
reddit.com โ€บ r/c_programming โ€บ what's the use of pointers-to-pointers?
r/C_Programming on Reddit: What's the use of pointers-to-pointers?
May 11, 2023 -

I already get the idea of plain old pointers to data. All a pointer is is a memory address where some data lives. The plain old pointers are generally used to iterate through things like arrays and tree nodes and to access data on the heap. But where are pointers-to-pointers actually useful (or triple pointers, etc.)? The only places I can think of where they are useful are for multidimentional arrays and navigating through lists of malloc'ed objects. Are there any other use cases where just a regular old pointer wouldn't be enough?

๐ŸŒ
BeginnersBook
beginnersbook.com โ€บ 2014 โ€บ 01 โ€บ c-pointer-to-pointer
C โ€“ Pointer to Pointer (Double Pointer) with example
Value of num is: 123 Value of num using pr2 is: 123 Value of num using pr1 is: 123 Address of num is: XX771230 Address of num using pr2 is: XX771230 Address of num using pr1 is: XX771230 Value of Pointer pr2 is: XX771230 Value of Pointer pr2 using pr1 is: XX771230 Address of Pointer pr2 is: 66X123X1 Address of Pointer pr2 using pr1 is: 66X123X1 Value of Pointer pr1 is: 66X123X1 Address of Pointer pr1 is: XX661111 ยท There are some confusions regarding the output of this program, when you run this program you would see the address similar to this: 0x7fff54da7c58.
๐ŸŒ
Eskimo
eskimo.com โ€บ ~scs โ€บ cclass โ€บ int โ€บ sx8.html
Chapter 22: Pointers to Pointers
char *string = "Hello, world!"; char *copystr; if(allocstr(strlen(string), &copystr)) strcpy(copystr, string); else fprintf(stderr, "out of memory\n"); (This is a fairly crude example; the allocstr function is not terribly useful. It would have been just about as easy for the caller to call ...
๐ŸŒ
Cplusplus
cplusplus.com โ€บ doc โ€บ tutorial โ€บ pointers
Cplusplus
Finally, the third statement, assigns the value contained in myvar to bar. This is a standard assignment operation, as already done many times in earlier chapters. The main difference between the second and third statements is the appearance of the address-of operator (&). The variable that stores the address of another variable (like foo in the previous example) is what in C++ is called a pointer.
๐ŸŒ
C Programming
c-lang.thiyagaraaj.com โ€บ home โ€บ c programs โ€บ c pointer example programs โ€บ pointer to pointer or double pointer example in c
Pointer to Pointer or Double Pointer Example in C - C Programming
June 30, 2026 - This is an example program in c pointer example programs. Read the concept first: C Pointers, then study the code and output below. Pointer to Pointer locates/store to another pointer variable address.
Top answer
1 of 6
14

When to use Pointer-to-Pointer in C++?

I'd say it is better to never use it in C++. Ideally, you will only have to use it when dealing with C APIs or some legacy stuff, still related to or designed with C APIs in mind.

Pointer to pointer has pretty much been made obsolete by the C++ language features and the accompanying standard library. You have references for when you want to pass a pointer and edit the original pointer in a function, and for stuff like a pointer to an array of strings you are better off using a std::vector<std::string>. The same applies for multidimensional arrays, matrices and whatnot, C++ has a better way of dealing with those things than cryptic pointers to pointers.

2 of 6
13

When you want to change the value of variable passed to a function as the function argument, and preserve updated value outside of that function, you require pointer(single pointer) to that variable.

void modify(int* p)
{
  *p = 10;
}

int main()
{
  int a = 5;
  modify(&a);
  cout << a << endl;
}

Now when you want to change the value of the pointer passed to a function as the function argument, you require pointer to a pointer.

In simple words, Use ** when you want to preserve (OR retain change in) the Memory-Allocation or Assignment even outside of a function call. (So, Pass such function with double pointer arg.)

This may not be a very good example, but will show you the basic use:

void safe_free(int** p) 
{ 
  free(*p); 
  *p = 0; 
}

int main()
{
  int* p = (int*)malloc(sizeof(int));
  cout << "p:" << p << endl;
  *p = 42;
  safe_free(&p);
  cout << "p:" << p << endl;
}
๐ŸŒ
Upgrad
upgrad.com โ€บ home โ€บ tutorials โ€บ software & tech โ€บ pointer to pointer in c
Mastering Pointer to Pointer in C: Syntax & Examples
April 30, 2025 - It allows you to reference a pointer that points to another pointer, creating a two-level indirection. ... In this example, ptr is a pointer to another pointer that eventually points to an integer.
Top answer
1 of 16
586

If you want to have a list of characters (a word), you can use char *word

If you want a list of words (a sentence), you can use char **sentence

If you want a list of sentences (a monologue), you can use char ***monologue

If you want a list of monologues (a biography), you can use char ****biography

If you want a list of biographies (a bio-library), you can use char *****biolibrary

If you want a list of bio-libraries (a ??lol), you can use char ******lol

... ...

yes, I know these might not be the best data structures


Usage example with a very very very boring lol

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int wordsinsentence(char **x) {
    int w = 0;
    while (*x) {
        w += 1;
        x++;
    }
    return w;
}

int wordsinmono(char ***x) {
    int w = 0;
    while (*x) {
        w += wordsinsentence(*x);
        x++;
    }
    return w;
}

int wordsinbio(char ****x) {
    int w = 0;
    while (*x) {
        w += wordsinmono(*x);
        x++;
    }
    return w;
}

int wordsinlib(char *****x) {
    int w = 0;
    while (*x) {
        w += wordsinbio(*x);
        x++;
    }
    return w;
}

int wordsinlol(char ******x) {
    int w = 0;
    while (*x) {
        w += wordsinlib(*x);
        x++;
    }
    return w;
}

int main(void) {
    char *word;
    char **sentence;
    char ***monologue;
    char ****biography;
    char *****biolibrary;
    char ******lol;

    //fill data structure
    word = malloc(4 * sizeof *word); // assume it worked
    strcpy(word, "foo");

    sentence = malloc(4 * sizeof *sentence); // assume it worked
    sentence[0] = word;
    sentence[1] = word;
    sentence[2] = word;
    sentence[3] = NULL;

    monologue = malloc(4 * sizeof *monologue); // assume it worked
    monologue[0] = sentence;
    monologue[1] = sentence;
    monologue[2] = sentence;
    monologue[3] = NULL;

    biography = malloc(4 * sizeof *biography); // assume it worked
    biography[0] = monologue;
    biography[1] = monologue;
    biography[2] = monologue;
    biography[3] = NULL;

    biolibrary = malloc(4 * sizeof *biolibrary); // assume it worked
    biolibrary[0] = biography;
    biolibrary[1] = biography;
    biolibrary[2] = biography;
    biolibrary[3] = NULL;

    lol = malloc(4 * sizeof *lol); // assume it worked
    lol[0] = biolibrary;
    lol[1] = biolibrary;
    lol[2] = biolibrary;
    lol[3] = NULL;

    printf("total words in my lol: %d\n", wordsinlol(lol));

    free(lol);
    free(biolibrary);
    free(biography);
    free(monologue);
    free(sentence);
    free(word);
}

Output:

total words in my lol: 243
2 of 16
227

One reason is you want to change the value of the pointer passed to a function as the function argument, to do this you require pointer to a pointer.

In simple words, Use ** when you want to preserve (OR retain change in) the Memory-Allocation or Assignment even outside of a function call. (So, Pass such function with double pointer arg.)

This may not be a very good example, but will show you the basic use:

#include <stdio.h>
#include <stdlib.h>

void allocate(int **p)
{
    *p = (int *)malloc(sizeof(int));
}

int main()
{
    int *p = NULL;
    allocate(&p);
    *p = 42;
    printf("%d\n", *p);
    free(p);
}
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ cplusplus โ€บ cpp_pointer_to_pointer.htm
C++ Pointer to Pointer (Multiple Indirection)
A variable that is a pointer to a pointer must be declared as such. This is done by placing an additional asterisk in front of its name. For example, following is the declaration to declare a pointer to a pointer of type int โˆ’
๐ŸŒ
CodeProject
codeproject.com โ€บ articles โ€บ Pointer-to-Pointer-and-Reference-to-Pointer
Codeproject
Disclaimer: References to any specific company, product or services on this Site are not controlled by GoDaddy.com LLC and do not constitute or imply its association with or endorsement of third party advertisers.
๐ŸŒ
guvi.in
studytonight.com โ€บ c โ€บ pointer-to-pointer.php
Pointer to Pointer in C Programming
Here, we have used two indirection operator(*) which stores and points to the address of a pointer variable i.e, int *. If we want to store the address of this (double pointer) variable p1, then the syntax would become: