Sunday, November 16, 2008

Array of Pointers

ARRAY OF POINTERS

The way there can be an array of ints or an array of floats, similarly there can be an array of pointers. Since a pointer variable always contain an address, an array of pointers would be nothing but collection of addresses. The addresses present in the array of pointers can be addresses of isolated variables or addresses of array elements or any other addresses. All rules that apply to an ordinary array apply to the array of pointers as well.

eg. main ( )

{

int * arra [ 4 ];

int i = 31, j = 5, k = 19, L = 71, m;

arra [0] = & i ;

arra [1] = & j ;

arra [2] = & k ;

arra [3] = & l ;

}

i j

3 6485

6485 3276

k

3276

7234


for (m=0; m<=3 ; m+ +)

printf (“\n% d”, * (arr[m])) ;

}

The output will be -
31
5
19
71
i j k l
31 5 19 71
4008 5116 6010 7118
arr[0] arr[1] arr[2] arr[3]
4008 5116 6010 7118
7602 7604 7606 7608

No comments: