I am a bit confused about the dynamic allocation of a 3d array. Right now, I'm just allocating one large block of memory as follows:
int height = 10;
int depth = 20;
int width = 5;
int* arr;
arr = new int[height * width * depth];
Now I would like to change the value in a 3D array, say:
//arr[depth][width][height]
arr[6][3][7] = 4;
However, I cannot use the above code to change the value. How can I use one index to access an element at a depth of position = 6, width = 3, height = 7?
arr[?] = 4;
Is there a better way to dynamically allocate a 3D array?
source
share