Pointer to Pointer or Double Pointer Example Program In C


  • Pointer to Pointer locates/store to another pointer variable address.
  • The dereference operator or indirection operator, noted by an asterisk ("*"), is also a unary operator in c languages that uses for pointer variables.
  • Double Pointer or Pointer to Pointer need to place a ** before the name of the double pointer.


data_type **pointer_variable;

Pointer to Pointer or Double Pointer Example Program

/*##Pointer to Pointer or Double Pointer Example Program with Reference operator (&) and Double Dereference operator (**)*/
/*##Simple Pointer Programs,Pointer to Pointer,Double Pointer*/

#include <stdio.h>

int main() {

  int var;
  //Pointer Variable Declaration for Integer Data Type 
  int *pt;

  //Double Pointer Variable Declaration with Double Dereference operator (**)
  int **dp;

  var = 100;

  printf("Address of var 			[&var ]	:%p\n", &var);
  printf("Value   of var 			[var ]	:%d\n\n", var);

  //& takes the address of var , Here now pt == &var, so *pt == var
  pt = &var;

  printf("Address of Pointer 		[pt  ] 	:%p\n", pt);
  printf("Value of Pointer 		[*pt ] 	:%d\n\n", *pt);

  //& takes the address of pt , Here now dp == &pt, so *pt == pt and **dp==var
  dp = &pt;

  printf("Address of Double Pointer 	[dp  ] 	:%p\n", dp);
  printf("Value of Double Pointer 		[*dp ] 	:%p\n\n", *dp);
  printf("Double Pointer Value 		[**dp] 	:%d\n", **dp);

  return 0;


Sample Output

Address of var                 [&var ] :0060FF08
Value   of var                  [var ]  :100

Address of Pointer              [pt  ]  :0060FF08
Value of Pointer                [*pt ]  :100

Address of Double Pointer       [dp  ]  :0060FF04
Value of Double Pointer         [*dp ]  :0060FF08

Double Pointer Value            [**dp]  :100