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?
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?
do you mean creating pointers to pointers using malloc...
like the one below..
Code:--------------------------------------- [ ] | | [ ]------[][][][] [ ]------[][][][] [ ]------[][][][] ----------------------------------------
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.
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];
Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }
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 }
Read this
Without a context for how you're calling your functions (like a main()), its hard to say what is wrong.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.