pointer to pointer in c

pointer to pointer in c

In previous session we learn that pointer is a variable that stores the address of any variable. And this pointer variable take up space in memory it also has an address, We can also store the address of pointer variable to another variable, it is know as pointer to pointer variable. similarly we can have pointer to pointer to pointer variables and this concept can go to any limit. But in conceptually or practice we used pointer to pointer only. it is used generally when pointer variable passing to function.

The syntax of declaration a pointer to pointer is

data_type **ptr;

In this example here variable ptr is a pointer to pointer variable that can store the address of pointer variable of data_type. Here the double esterisk used in the declaration indicated or inform to the compiler that pointer to pointer variable is declared. so now take the example with it

int a=34;
int *ptr=&a;
int **pptr=&ptr;

In this example first declare variable a and in the second statement pointer variable is declare of type int ptr and stored the address of variable a to the ptr pointer variable, In the last statement pointer to pointer variable is declare pptr which store address of pointer variable

pointer to pointer in c

/* dereferencing pointer variable */
#include<stdio.h>
int
main()
{
int a=56;
float b=8.5;
int *ptr1=&a;
float *ptr2=&b;
printf("value of ptr1= Address of a=%p\n",ptr1);
printf("value of ptr2= Address of b=%p\n",ptr2);
printf("Value of a=%d, %d, %d \n",a,*ptr1,*(&a));
printf("Value of b=%d, %d, %d \n",b,*ptr2,*(&b));
return 0;
}

value of ptr1= Address of a=0x7ffe590462c8
value of ptr2= Address of b=0x7ffe590462cc
Value of a=56, 56, 56
Value of b=2147483626, 2060507616, 21