Setting pointers to NULL for 4D array

I'm currently working on a code that uses many 2-4D matrices.

For example, one of my 4D matrices is initialized like this:
double (*kse)[nIStats+1][nDofs-nDim+1][nDim+1]=new double[nEles+1][nIStats+1][nDofs-nDim+1][nDim+1]

I would like to set all of these pointers to NULL at first and then assign values to them as needed.

What is the simplest way of doing this?

Thanks!
Do you want assign NULL to pointers llike that double (*kse)[nIStats+1][nDofs-nDim+1][nDim+1] or assign zeroes to elements of arrays you allocate?
If you want to init elements of arrays to sero you should write

double (*kse)[nIStats+1][nDofs-nDim+1][nDim+1]=new double[nEles+1][nIStats+1][nDofs-nDim+1][nDim+1] {};


provided that your compiler supports the new C++ standard. Otherwise you should yourself to init arrays.
Last edited on
No, I want to set the pointers to point to NULL (so that they don't take up any space in memory), so that if I try and erase them later and they are not allocated, I do not get an error.
double (*kse)[nIStats+1][nDofs-nDim+1][nDim+1] = NULL;
Topic archived. No new replies allowed.