title: C question regarding pointers in a function
body: <p>I have two questions regarding this code.</p>
  
  <ol>
  <li><p>What does the <code>double*** pdata</code> and <code>int*** pmask</code> mean? A pointer to a pointer to a pointer?
  Why or when is this necessary?</p></li>
  <li><p><code>int</code> and <code>double</code> are different types, but are <code>double*</code> and <code>int*</code> also different. Can we operate on them without a cast?</p></li>
  </ol>
  
  <p>Here's the code I'm puzzled about:  </p>
  
  <pre><code>static int makedatamask(int nrows, int ncols, double*** pdata, int*** pmask)
      { int i;
        double** data;
        int** mask;
        data = malloc(nrows*sizeof(double*));
        if(!data) return 0;
        mask = malloc(nrows*sizeof(int*));
        if(!mask)
        { free(data);
          return 0;
        }
        for (i = 0; i &lt; nrows; i++)
        { data[i] = malloc(ncols*sizeof(double));
          if(!data[i]) break;
          mask[i] = malloc(ncols*sizeof(int));
          if(!mask[i])
          { free(data[i]);
            break;
          }
        }
        if (i==nrows) /* break not encountered */
        { *pdata = data;
          *pmask = mask;
          return 1;
        }
        *pdata = NULL;
        *pmask = NULL;
        nrows = i;
        for (i = 0; i &lt; nrows; i++)
        { free(data[i]);
          free(mask[i]);
        }
        free(data);
        free(mask);
        return 0;
      }
  </code></pre>