34 Programming and Data Structures
The statement on the previous page declares an array b [ ] which can hold four integer values. The
following program illustrates use of an array.
13 Write a program to declare, initialize an array. Display the elements of an array with their
addresses.
# include <stdio.h>
# include <conio.h>
void main ()
{
clrecr () j
int b[4J«{2,4,3,7};
printf (mnb[0] Value =%d Address=%u#r ,b [0] ,&b[0]);
printf (*nb [1] Value »%d Address »%u",b[l] ,&b[l]);
printf ("nb [2] Value «%d Address *%u",b[2] ,&b[2]);
pri^xtf ("nb[3] Value »%d Address -%u",b[3] ,&b[3])/
>
o m r y ji
1>I0} Value => 2 Address: 4090
b(l] Value = 4 Address: 4092
b[2) Value-a 3 Address: 4094
b(3] Value o 7 Address: 4096
Explanation In the above program an array b[4 ] is declared and initialized. The cout statement
displays the array elements with their addresses. The b [ 0 ] refers to first element; b [ 1 ] refers to second
element and so on. Fig. 2.5 shows element numbers, elements and addresses.
Fig. 2.5 Array elements in memory