C++ multidimensional arrays on the heap

array picture
Picture of the heap array.

When using C++, you cannot store large arrays in the stack, so you should use the heap memory. You do so by e.g. using the new keyword and using a pointer to the reserved memory in the heap.

Problems emerge when you have to use multidimensional arrays. I could not find elegant solutions that matched my personal taste. For example, see the solutions on Stack Overflow. So here is my solution:

struct array {
    int v[42][42];
array * sim = new array;
// initialize int array values to zero
for (int i=0; i<42; i++) {
    for (int j=0; j<42; j++) {
        sim->v[i][j] = 0;

This worked for me and I liked the syntax better than the other solutions, but YMMV.