# Pointers and arrays

• 03-07-2004
OttoDestruct
Pointers and arrays
Could anyone give me a crash course on using a dynamically allocated pointer array to use pointers within it to point to values in an array?
• 03-07-2004
vasanth
do you mean creating pointers to pointers using malloc...
like the one below..

Code:

```--------------------------------------- [  ]   |   | [  ]------[][][][] [  ]------[][][][] [  ]------[][][][] ----------------------------------------```
• 03-07-2004
OttoDestruct
Uh.. heres an attatched crappy photoshop of what I'm trying to do. Sorting an array using two pointer arrays full of pointers to the array, not values.
• 03-07-2004
Sebastiani
Re: Pointers and arrays
Quote:

Originally posted by OttoDestruct
Could anyone give me a crash course on using a dynamically allocated pointer array to use pointers within it to point to values in an array?

char ** array = new char* [size];
• 03-07-2004
OttoDestruct
Alright... I'm now getting core dumps and I can't see why.. then again I don't understand pointers at all... this is supposed to look at array and sort the pointers of pAscending without modifying whats inside array...

Code:

```void sortascend (int array[], int **pAscending) {   int i;   void exchangelargest (int[], int**, int);   for (i = 0; i < 5; i++)   exchangelargest (array, pAscending, i); } // sortascend  void exchangelargest (int array[], int **pAscending, int i) {   int walker;   int largest;   int *temp = *pAscending;   largest = i;     for (walker = i+1; walker <= 5; walker++)   {     if (array[walker] > array[largest])     largest = walker; // if   temp = *(pAscending+i);   *(pAscending+i) = *(pAscending+largest);   *(pAscending+largest) = temp;   } // for }```
• 03-08-2004
Salem