Search Result
Details here...

Pointer to a Pointer

Previous

Multidimensional Arrays - 2D and 3D Array

Next

Introduction to Structure


We know that, a pointer is a variable that holds the address of another variable. In the similar way, a pointer to a pointer is a variable that holds the address of a pointer.

Hence, a pointer to a pointer is the chain of pointers. Only one pointer holds the value of a particular variable pointed to, and the double pointer holds the address of the pointer. It can be represented as:
Pointer to a pointer in C | Coder's Lap Pointer to a Pointer in C


An example of a pointer to a pointer is:
int num = 10;
int *ptr = #
int **pptr = &ptr;
It can be represented as:
Pointer to a pointer Example in C | Coder's Lap Pointer to a pointer Example in C
In the above example, pptr is the pointer to a pointer, but not **pptr.

Pointer to a Pointer Example

C

#include <stdio.h>
int main()
{
int num = 10;
int *ptr = &num;
int **pptr = &ptr;
printf("The value of num = %d\n", num);
printf("The address of num = %d\n", ptr);
printf("The address of ptr = %d\n", pptr);
printf("The value of *ptr = %d\n", *ptr);
printf("The value of **ptr = %d\n", **pptr);
return 0;
}

Output

The value of num = 10
The address of num = 2000
The address of ptr = 5566
The value of *ptr = 10
The value of **ptr = 10
By darpan.kattel
Previous

Multidimensional Arrays - 2D and 3D Array

Next

Introduction to Structure