An array of pointers can be declared very easily.
int *p[10];
This declares an array of 10 pointers, each of which points to an integer.
Ex:
int* p[10];
int a = 10, b = 20, c =
30;
p[0] = &a;
p[1] = &b;
p[2] = &c;
In general, an array of
pointers can be used to point to an array of data items, with each element of
the pointer array pointing to an element of the data array. Data items can be
accessed either directly in the data array, or indirectly by dereferencing the
elements of the pointer array. The advantage of an array of pointers is that
the pointers can be reordered in any manner without moving the data items.
For example, the
pointer array can be reordered so that the successive elements of the pointer
array point to data items in a sorted order without moving the data items.
No comments:
Post a Comment