Best Division

Spread Your Knowledge

  • All topics
  • About us
  • Contact us
  • Privacy policy
  • Terms of service
  • Copyright
  • Facebook
  • Twitter
  • Instagram
  • Youtube
  • LinkedIn
  • Pinterest
  • Github
  • Tumblr

© 2026 Best Division

What Is a Pointer to a Pointer in C? Double Pointers

C
Jayant Kumar
Jayant Kumar@jayantkumar314
PublishedDec 6, 2026
8 min read

A pointer to a pointer in C, also called a double pointer, is a variable that stores the address of another pointer. You declare it with two asterisks, for example int **pp, and you reach the final value by dereferencing twice with **pp. A double pointer in C is mainly used when a function must change a pointer that belongs to the caller, and when working with arrays of pointers such as lists of strings.

The idea follows directly from ordinary pointers: a pointer is a variable, so it lives at an address, and that address can be stored in another pointer.

Table of Contents

  • Declaring and using a double pointer
  • Why a function needs a pointer to a pointer
  • Pointer to pointer and arrays of strings
  • Dynamic two-dimensional arrays with double pointers
  • Common mistakes with double pointers
  • Frequently Asked Questions
    • What does int **pp mean in C?
    • When should I use a pointer to a pointer?
    • Is a double pointer the same as a 2D array?
    • How many levels of pointers can I have?
  • Summary
  • Related Articles

Declaring and using a double pointer

Each level of * adds one level of indirection. Start with an int, then a pointer to it, then a pointer to that pointer:

c
text

The addresses will differ on your machine. The key reading rules are:

ExpressionTypeMeaning
ppint **Address of the pointer p
*ppint *The pointer p itself
**ppintThe integer value

Why a function needs a pointer to a pointer

C passes arguments by value. If a function receives an int * and assigns a new address to it, only its local copy changes. To let the function change the caller's pointer, pass the address of that pointer, which is an int **.

The classic case is allocation inside a helper function:

c
text

Inside allocate_array, *out = malloc(...) writes the new address into the caller's data. If the parameter were a plain int *, the caller's data would remain NULL and the memory would leak. The parentheses in (*out)[i] are required because [] binds tighter than *.

Pointer to pointer and arrays of strings

A second common use is an array of pointers. Each element is a pointer to the first character of a string, and the array name decays to a pointer to its first element, which has type char **. You have already seen this in main:

c

argv is a char **: it points to an array of char *, each pointing to one command-line argument. The same shape is used by lists of names, tables of messages and environment variables.

c
text

Dynamic two-dimensional arrays with double pointers

A T ** can also represent a table whose rows are allocated separately. This gives rows of independent lengths and the familiar grid[r][c] syntax:

c
text

You must free every row first and then the array of row pointers. Note that this layout is not one contiguous block, so it is not the same type as int grid[3][4], and you cannot pass one where the other is expected.

Common mistakes with double pointers

  • Forgetting the extra level: passing data instead of &data to a function that expects int ** is a type error, and ignoring the warning leads to crashes.
  • Dereferencing too early: **pp is invalid if p is NULL or uninitialised. Check *pp before the second dereference.
  • Freeing in the wrong order: free each row before freeing the row-pointer array.
  • Confusing const char ** with char **: C does not convert between them implicitly, so a function taking const char ** cannot be called with a plain char ** without a cast.
  • Going deeper than needed: a triple pointer is rarely the clearest design. A struct that holds the data is usually easier to read.

Frequently Asked Questions

What does int **pp mean in C?

It declares pp as a pointer to a pointer to int. The variable pp holds the address of an int *, and **pp is the int at the end of the chain.

When should I use a pointer to a pointer?

Use it when a function must modify a pointer owned by the caller, such as allocating memory or advancing a list head, and when you work with arrays of pointers like char **argv.

Is a double pointer the same as a 2D array?

No. A 2D array such as int a[3][4] is one contiguous block. An int ** points to separate row allocations, so the two types are not interchangeable.

How many levels of pointers can I have?

The C standard guarantees support for a reasonable depth, and compilers accept far more than you will ever need. In practice, stop at two levels and use structs beyond that.

Summary

A pointer to a pointer is a variable that holds the address of another pointer, declared with ** and read by dereferencing twice. Use it when a function has to change the caller's pointer, as in allocation helpers, and when you work with arrays of pointers such as argv and string tables. Check for NULL at each level, free memory in reverse order of allocation, and keep indirection to two levels where possible.

Related Articles

  • How to Swap Two Numbers Using Pointers in C
  • What is a null pointer in C?
  • Learn C: Complete Study Roadmap from Beginner to Advanced
Share

Similar posts

  • How to Swap Two Numbers Using Pointers in C
  • What Is the Relationship Between Arrays and Pointers in C?
  • How Does Pointer Arithmetic Work in C?
  • What Is a Pointer in C and How Do You Declare One?
  • How to Format Strings Safely with snprintf in C
  • How to Split a String with strtok in C
  • How to Convert Strings to Numbers with strtol in C
  • How Do You Check if a String Is a Palindrome in C?