Double Pointer in C

By | February 18, 2023

In C, a double pointer is a variable that stores the address of a pointer. It is also known as a pointer-to-pointer. Double pointers are useful when you need to modify the value of a pointer itself, not just the value it points to.

Declaring Double Pointer in C:
Here is an example of how to declare a double pointer in C:

int **pptr;

In the above example, pptr is a double pointer to an integer type. It can store the address of a pointer to an integer.

To access the value that the double pointer is pointing to, you need to dereference it twice. Here’s an example:

int *ptr;
int a = 10;

ptr = &a;  // pointer to the variable a
pptr = &ptr;  // double pointer to the pointer ptr

// Accessing the value of variable a using the double pointer
printf("%d", **pptr);  // Output: 10

In the above example, ptr is a pointer to the variable a, and pptr is a double pointer to the pointer ptr. To access the value of a using pptr, we need to dereference pptr twice using the ** operator.

Double pointers are commonly used in data structures like linked lists and trees, where you need to modify the pointers that link the nodes. They can also be used to create dynamic two-dimensional arrays.

Please write comments below if you find anything incorrect, or you want to share more information about the topic discussed above. A gentle request to share this topic on your social media profile.

Author: Mithlesh Upadhyay

I hold an M.Tech degree in Artificial Intelligence (2023) from Delhi Technological University (DTU) and possess over 4 years of experience. I worked at GeeksforGeeks, leading teams and managing content, including GATE CS, Test Series, Placements, C, and C++. I've also contributed technical content to companies like MarsDev, Tutorialspoint, StudyTonight, TutorialCup, and Guru99. My skill set includes coding, Data Structures and Algorithms (DSA), and Object-Oriented Programming (OOPs). I'm proficient in C++, Python, JavaScript, HTML, CSS, Bootstrap, React.js, Node.js, MongoDB, Django, and Data Science.