Pointer to Pointer Program in C

Pointer to Pointer Program in C

//pointer a special type of variable which store address of another varable(referencing like p=&a). and by pointer de-referncing that varible a by *p
//pointer to pointer or chain of pointer

#include<stdio.h>

main()
 {

  int a=100;     //simple variable
  int *p;           //pointer p special variable which store another variable address
  int **p1;
  int ***p2;
   p=&a;
   p1=&p;
   p2=&p1;
 
  printf("\n%d\n",a);    //value of a

   printf("%d\n\n",*p);          //print value at address of a..which is 100

   printf("%d\n\n",**p1);       //print value at address of a..which is 100

   printf("%d\n\n",***p2);       //print value at address of a..which is 100

   printf("%p\n\n",*p1);           //print value at address of p.means value of p.

   printf("%p\n\n",*p2);           //print value at address of p1.means value of p1.

     printf("%p\n\n",**p2);         //print value at address of p.means value of p.


     printf("%p\n",p);      //address of p("%p", is format spicifier for prnting address.we also use "%x", or "%u", but in c "%p", is specialy for printing address)

      printf("%p\n\n",&a);     //address of a
       
 }

Related Posts