Friday, 30 March 2012

Pointer of pointer


Pointer to pointer(Pointer of pointer)

It is also possible to make a pointer to point another pointer , It creates chain of pointers.


 As shown in above figure the pointer variable ptr2 contains the address of pointer variable ptr1, which points to the location that contains the desired value. This is known as multiple indirection.
Fig:


Pointer to pointer declared as follows:
   int  **ptr2;

This declaration tells the compiler that ptr2 is a pointer to pointer of integer type.

Note :   that the pointer ptr2 is not a pointer to an integer , but rather a pointer to an integer pointer.
Ex;
     void main()
       {
            int  x,*ptr1,*ptr2;
            x=100;
            ptr1=&x;
            ptr2=&ptr1;
           printf(“\n Value of x     :  %d”,x);
           printf(“\n Value of ptr1 :  %u”,ptr1);
           printf(“\n value of ptr2  :  %u”,ptr2);
           printf(“\n Value of x     :  %d”,*ptr1);
           printf(“\n Value of x     :  %d”,**ptr2);
    }

Posted By : Ruchita Pandya

No comments:

Post a Comment