304 Programming and Data Structures
for(i=0;'<5/'i++)
{
printf ("nt%d at location",*(*p+i));
printf ("t% u at location ",*(p+i));
printf ("%u",p+i);
I
printf ("nn Integer requires 2 bytes, address require 4 bytes");
O UTPU T;
Oat location 4036 at location 4046
1 at location 4038 at location 4050
2 at location 4040 at location 4054
3 at location 4042 at location 4058
4 at location 4044 at location 4062
Integer requires 2 bytes, address require 4 bytes
Explanation In the above program the first f o r loop assigns addresses of elements of an integer
array to a pointer array The f i r s t p r i n t f () statement prints element, second displays address of
element and the third displays address of the address i.e. address of the pointer. Thus, it is clear from
the above example that an integer requires two b y tes and pointer requires fou r bytes.
9.8 POINTERS TO POINTERS
Pointer is known as a variable containing address of another variable. The pointer variables also have
an address. The pointer variable containing address of another pointer variables is called as pointer
to pointer. This chain can be continued to any extent.
The program given below illustrates the concept of pointer to pointer.
9.27 Write a program to print value of a variable through pointer and pointer to pointer.
# include <stdio.h>
# include <conio.h>
void main ()
{
int a«2,*p,**q;
p=&a;
q**p;
clrscrO ;
printf ("n Value of a - %d Address of a=%u",a,$x.a);
printf ("n Through *p Value of a - %d Address ofa=%u",*p,p);
printf ("n Through **q Value of a - %d Address ofa=%d",**q,*q);