Please help me to understand this function to allocate a 2D array.
int** ArrayAlloc(int rows, int cols, int size)
{
int i;
int** pp;
pp = (int**) malloc(rows * sizeof(int*));
/* check for error */
pp[0] = (int*) malloc(rows * cols * size);
/* check for error */
for(i = 1; i < rows; ++i)
pp = &(pp[0][i * cols * size]);
return pp;
}
int** ArrayAlloc(int rows, int cols, int size)
{
int i;
int** pp;
pp = (int**) malloc(rows * sizeof(int*));
/* check for error */
pp[0] = (int*) malloc(rows * cols * size);
/* check for error */
for(i = 1; i < rows; ++i)
pp = &(pp[0][i * cols * size]);
return pp;
}