302 Programming and Data Structures
OR
9.24 Write a program to display array elements and their address. Use array name it self as
a pointer.
# include <stdio.h>
# include <conio.h>
void main ()
{
int i;
int a(]£3]-{{l,2,3},{4,5,6},{7,8,9}};
clrscrO;
printf ("tElements o f An Array with their addresses.nn ");
for (i=0,-i<9,‘i++)
printf ("%8u"Aa[0]l0}+i);
printf ( " [%d]",*(&a[0J[0]+i));
if(i==2 I I i==5)
printf (" n ");
}
}
Q V T E U T ;
Elements of An Array with their addresses.
1(4052] 2 [4054] 3 [4056]
4[4058] 5(4060] 6 [4062]
7 [4064] 8140661 9 [4068]
Explanation The logic of the program is same as the previous one. The only difference is that the
array name itself is used as a pointer. The i f statement inserts a line after displaying every three
elements.
9.7 ARRAY OF POINTERS
So far we have studied array of different standard data types such array of
in t, flo a t , characters
etc. In the same way the 'C ' language also supports array of pointers. It is nothing but a collection of
addresses. Here, we store address of variables for which we have to declare an array as a pointer.
9.25 Write a program to store addresses of different elements of an array-using array of
pointers.
# include <stdio.h>
# include <conio.h>
void main ()
{
int *arrp[3];