Write a C Program to understand pointer to pointer. Here’s a Simple Program which shows an example to understand pointer to pointer in C Programming Language.
A pointer to a pointer is a form of multiple indirection, or a chain of pointers. Normally, a pointer contains the address of a variable.
When we define a pointer to a pointer, the first pointer contains the address of the second pointer, which points to the location that contains the actual value
When a target value is indirectly pointed to by a pointer to a pointer, accessing that value requires that the asterisk operator be applied twice.
The declaration of a pointer-to-pointer looks like :
int **ipp;
where the two asterisks indicate that two levels of pointers are involved.
Below is the source code for C Program to show an example of pointer to pointer which is successfully compiled and run on Windows System to produce desired output as shown below :
SOURCE CODE : :
/* Program to understand pointer to pointer*/
#include<stdio.h>
int main( )
{
int a = 5;
int *pa;
int **ppa;
pa = &a;
ppa = &pa;
printf("Address of a = %p\n", &a);
printf("Value of pa = Address of a = %p\n", pa);
printf("Value of *pa = Value of a = %d\n", *pa);
printf("Address of pa = %p\n", &pa);
printf("Value of ppa = Address of pa = %p\n", ppa);
printf("Value of *ppa = Value of pa = %p\n", *ppa);
printf("Value of **ppa = Value of a = %d\n", **ppa);
printf("Address of ppa = %p\n", &ppa);
return 0;
}
OUTPUT : :
Address of a = 000000000062FE4C
Value of pa = Address of a = 000000000062FE4C
Value of *pa = Value of a = 5
Address of pa = 000000000062FE40
Value of ppa = Address of pa = 000000000062FE40
Value of *ppa = Value of pa = 000000000062FE4C
Value of **ppa = Value of a = 5
Address of ppa = 000000000062FE38
Pointer to Pointer :
Below is the source code for C Program to show an example of pointer to pointer which is successfully compiled and run on Windows System to produce desired output as shown below :
SOURCE CODE : :
OUTPUT : :
need an explanation for this answer? contact us directly to get an explanation for this answer