Pointer-to-pointer-in c .

In this session i have discussed pointer to pointer in C .

The pointer variable is used to store the address of other variable . It is also store the address of other pointer this is called the pointer to pointer or double pointer or pointer chaining .

In the below diagram the ptr1 is double pointer because it stored the address of ptr2 pointer and ptr2 stored the address of a variable .

mvc image



Example : Write a program that demonstrate the pointer to pointer .

    int main()
          int x=10;
          int*ptr2; // normal pointer
          int**ptr1; // double pointer
          ptr2=&x;   // assign the address of x into ptr2
          ptr1=&ptr2; //assign the address of ptr2 into ptr1
          printf("x : %d",x);
          printf("ptr2 : %d\n",*ptr2);
          printf("ptr1 : %d\n",**ptr1);
          printf("address of x : %u\n",&x);
          printf("address of x using ptr2 : %u\n",ptr2);
          printf("address of x using ptr1 : %u\n",*ptr1);
          return 0;
    OUTPUT : x : 10
             ptr2 : 10
             ptr1 : 10
             address of x : 2686728
             address of x using ptr2 : 2686728
             address of x using ptr1 : 2686728

Welcome to AndroidATPoint.

back image                     next image