POINTERS TO POINTERS


POINTERS TO POINTERS:

            A pointer is a variable which contains address of another variable. Pointer variables also have an address. The pointer variable containing address of another pointer variable is called pointer to pointer.

Syntax:

            Data type **variable;
Eg:-
            int a=10;
            int *p1=&a;
            int **p2=&p1;


   

Here, p1 is a pointer variable which stores the address of a i.e., 5000. This is also stored in another address 6000. the variable p2 stores the address of a pointer p1. Thus, p2 is known as pointer to pointer. Here the data type indicates the value that is stored in address of the pointer variable whose address is stored in pointer to pointer variable.

Thus, the chain of pointers can be extended to any extent.

Eg., prog:-
            #include<stdio.h>
            #include<conio.h>
            void main()
{
             int a=5, *p1, **p2;
p1=&a;
p2=*p1;
printf(“address of a =%u”, p1);
printf(“address of p1=%u”,p2);
      printf(“value of a=%d”, **p2);
      }

No comments:

Post a Comment