Double Pointer
Published Feb 10, 2025
Contribute to Docs
In C, a double pointer is a pointer that holds the memory address of another pointer. It allows indirect access to the value of a variable.
Syntax
A double pointer is declared using two asterisks (**
) before the pointer variable name:
type **name
type
: The type of data the double pointer will point to (e.g.,int
,char
, etc.).name
: The identifier for the double pointer.
Example
The following example demonstrates how a double pointer is declared and used:
# include <stdio.h>int main() {int value = 35;int *pointer = &value; // Pointer to an integer (stores the address of 'value')int **doublePointer = &pointer; // Double pointer to an integer pointer (stores the address of 'pointer')// Printing the valuesprintf("Value of value: %d\n", value); // Direct access to valueprintf("Value of *pointer: %d\n", *pointer); // Dereferencing pointer to access valueprintf("Value of **doublePointer: %d\n", **doublePointer); // Dereferencing double pointer twice to access value// Printing the addressesprintf("Address of value: %p\n", (void*)&value); // Address of the variable 'value'printf("Address of pointer: %p\n", (void*)&pointer); // Address of the pointer 'pointer'printf("Address of doublePointer: %p\n", (void*)&doublePointer); // Address of the double pointer 'doublePointer'return 0;}
The above code will give the following output:
Value of value: 35Value of *pointer: 35Value of **doublePointer: 35Address of value: 0x7ffcbffdcc14Address of pointer: 0x7ffcbffdcc18Address of doublePointer: 0x7ffcbffdcc20
In the example:
value
is an integer variable.pointer
is a pointer tha stores the address ofvalue
.doublePointer
is a double pointer that stores the address of the pointer.
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.