You can use a pointer to a pointer to allocate two dimensional arrays.
Code:
int **buf, rows = 10, cols = 10;
buf = new int*[rows];
for(int i = 0; i < rows; i++)
buf[rows] = new int[cols];
You can use a pointer to a pointer if you need to pass a pointer by reference. (Alternately, you could just use a reference, but C doesn't have that.)
Code:
void func(int **a) //double pointer, valid C code
{
*a = (int*)1;
}
void func(int *&a) //reference to a pointer, invalid C code
{
a = (int*)2;
}
int main()
{
int *a = NULL;
func(&a); //pass the address of the pointer
if(a == (int*)1)
std::cout << "1" << std::endl;
func(a); //pass the pointer
if(a == (int*)2)
std::cout << "2" << std::endl;
return 0;
}
Just like any tool, they have their occasional uses. I prefer to use STL to take care of that memory management stuff.