C ++ test if the array has been initialized


I have a double** mat, and I want to test whether it has already been initialized. If not, I allocate memory space for it. Is this working? :

      mat = new double*[dim1];
      for(int i = 0 ; i < dim1 ; i++)
          mat[i] = new double[dim2];

What am I testing with if(! mat) ?


what that you are checking in:

if (!mat)

is if the location mat is pointing to is NULL (0).

this well work just if the default for pointers is zero, of if you have declared your pointer like this:

double ** mat = NULL;