What are they really good for? In every case of pointers that I've seen, just one pointer would work fine yet the programmer chose a pointer to a pointer. Why would I want to use that instead of just one pointer when one would work fine?
Printable View
What are they really good for? In every case of pointers that I've seen, just one pointer would work fine yet the programmer chose a pointer to a pointer. Why would I want to use that instead of just one pointer when one would work fine?
Sometimes you wan't to pass a pointer to a function as a reference (so that the pointer value can be changed).
Say that the pointer points to the pixels in an image and you have a function for loading an image from disk imgLoad(), this function might take as an argument a pointer to a pointer..
imgLoad(void** pixels);
This way you can allocate memory inside the function, and make the void* pixels pointer point to the new memory.. caling the function with:
PIXELS* myPixels;
imgLoad(&myPixels);
This can be usefull sometimes..
Besides that double arrays are a good example, as pointed out by the vVv. Note that you don't have to make all row's in a double array equaly long.. You can have one loking like:
******
***
*****
**
This is hard to do with [row*width + col] in a single array beeing used as a double..
- Anders
- Anders