Skip to main content

Posts

Showing posts with the label Array of Pointers

Array of Pointers

Array of pointers is simply an array which can store address. Like we declare an array , array of pointers can be declared very easily.   int *p[10]; // will create an array of 10 pointers, each of which points to an integer. We can make them point to integer variable Let int a=10,b=20,c=30; p[0]=&a;p[1]=&b;p[2]=&c; this will make the pointer array element p[0],p[1] and p[2] points to integer variables a,b and c respectively. 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. The advantage of an array of pointers is that the pointers can be reordered without moving the data items. Reordering pointers is relatively fast compared to reordering large data items such as data records or strings.Sorting an array of strings requires swapping the strings which is complex. The solution is to use to pointers and order the pointers based on the strings order.