I have the following code in come C++ I need to translate to C#
int** _cartesianProduct(int sizeA, int sizeB) {
int** array = (int**)malloc(sizeof(int*) * sizeA * sizeB + sizeof(int) * 2 * sizeA * sizeB);
int* ptr = (int*)(array + sizeA * sizeB);
for (int i = 0; i < sizeA * sizeB; ++i)
array[i] = (ptr + 2 * i);
for (int i = 0; i < sizeA; ++i)
for (int k = 0; k < sizeB; ++k) {
array[i * sizeB + k][0] = i;
array[i * sizeB + k][1] = k;
}
return array;
}
This creates an array of "Cartesian products" for all possible combinations of the numbers passed to it. My specific confusion here is what this block is doing?
int* ptr = (int*)(array + sizeA * sizeB);
for (int i = 0; i < sizeA * sizeB; ++i)
array[i] = (ptr + 2 * i);
Or even more specifically, this line int* ptr = (int*)(array + sizeA * sizeB);
?