Pointer to pointer in c
We can also store the address of another pointer in c.
This tutorial explains pointer to pointer concept with examples.
Where, ptr is a pointer which is holding the address of variable a.
If we need to hold the address of ptr, what will be the solution?
Pointer to Pointer.
Declaration of pointer to pointer (double pointer)
We need to use ** to declare the pointer to pointer(double pointer) variable.
** declaration indicates that I am a pointer but I am not pointing to a variable rather pointing to the address of another pointer.
Visual Representation of the above code
Referencing and dereferencing a double pointer
Assigning an address to the pointer.
Accessing the value stored at the pointer.
*ptr -> *1024 -> value stored at the memory 1024 is 10 ->10
**dptr -> *(*2024)-> value stored at the memory address 2024 is 1024 -> *1024->value stored at the memory address 1024 is 10 -> 10
Find the output
Using the above diagram, can you find the output of the program?
Address of a = ____________
ptr is pointing to the address = ____________
dptr is pointing to the address = ___________
Value of a = ___________
*ptr = ___________
**dptr = ____________