A pointer variable stores the address of another pointer variable; this is referred to as a pointer to a pointer variable in C.
It is a type of multiple indirections, also known as a chain of pointers. A pointer contains the address of a variable, and when a pointer to a pointer is defined, the first pointer contains the address of the second pointer, which points to the actual variable’s address.
Let us understand this better with the help of an example:
int b=10;
int *p=&b;
int **ptr=&p;
here:
Using ptr we can now access the pointer p as well as the value of variable b.
#include<stdio.h>
int main()
{
int b;
int *p;
int **ptr;
b = 10;
/* take the address of b */ p = &b;
/* take the address of p using address of operator & */ ptr = &p;
/* take the value using ptr */ printf("Value of b = %d\n", b );
printf("Value available at *p = %d\n", *p );
printf("Value available at **ptr = %d\n", **ptr);
/* take the address */ printf("Value of &b = %u\n", &b );
printf("Value available at p = %u\n", p );
printf("Value available at &p = %u\n", &p );
printf("Value available at &ptr = %u\n", &ptr);
printf("Value available at ptr = %u\n", ptr);
printf("Value available at *ptr = %u\n", *ptr);
return 0;
}
Value of b = 10
Value available at *p = 10
Value available at **ptr = 10
Value of &b = 2051687924
Value available at p = 2051687924
Value available at &p = 2051687928
Value available at &ptr = 2051687936
Value available at ptr = 2051687928
Value available at *ptr = 2051687924
Note: also read about the Pointer to structure
If you like my post please follow me to read my latest post on programming and technology.
https://www.instagram.com/coderz.py/
https://www.facebook.com/coderz.py
Staying up to the mark is what defines me. Hi all! I’m Rabecca Fatima a keen learner, great enthusiast, ready to take new challenges as stepping stones towards flying colors.
Given an integer A. Compute and return the square root of A. If A is…
Given a zero-based permutation nums (0-indexed), build an array ans of the same length where…
A heap is a specialized tree-based data structure that satisfies the heap property. It is…
What is the Lowest Common Ancestor? In a tree, the lowest common ancestor (LCA) of…
A Binary Search Tree (BST) is a type of binary tree that satisfies the following…