title: Error in memset() a 3D array
body: <p>I dynamically allocate a 3D array:</p>
  
  <pre><code>int n1=2,n2=5,n3=3;
  int in1,in2,in3;
  float ***a;
  a = (float ***)malloc(n1*sizeof(float **));
  for (in1=0;in1&lt;n1;in1++)
      a[in1] = (float **)malloc(n2*sizeof(float *));
  for (in1=0;in1&lt;n1;in1++)
      for (in2=0;in2&lt;n2;in2++)
          a[in1][in2] = (float *)malloc(n3*sizeof(float));
  </code></pre>
  
  <p>After that I want to initialize this 3D array. The conventional way is:</p>
  
  <pre><code>for (in1=0; in1&lt;n1; in1++)            
      for (in2=0; in2&lt;n2; in2++)      
          for (in3=0; in3&lt;n3; in3++)  
              a[in1][in2][in3] = 1.0f;
  </code></pre>
  
  <p>However, if I want to use <code>memset()</code> to initialize the array, it seems unfeasible because the first input is *ptr. So if I write</p>
  
  <pre><code>memset(a[0],1,n1*n2*n3*sizeof(float));
  </code></pre>
  
  <p>The first input a[0] is a **ptr, which is wrong.
  If I write:</p>
  
  <pre><code>memset(a[0][0],1,n2*n3*sizeof(float));
  </code></pre>
  
  <p>The first input is a *ptr, but there's no n1-dimension any more.</p>
  
  <p>So I'm wondering if <code>memset()</code> can only be used to initialize a 2D matrix?</p>
  
  <p>** I understand memset can't be used on 3D array, but for 2D array I think it's feasible. Here's an example:</p>
  
  <pre><code>int n1=2,n2=5;
  int in1,in2;
  float **a;
  a = (float **)malloc(n1*sizeof(float *));
  for (in1=0;in1&lt;n1;in1++)
      a[in1] = (float *)malloc(n2*sizeof(float));
  memset(a[0],0,n1*n2*sizeof(float));
  free(*a);free(a);
  </code></pre>
  
  <p>This is also not contiguous memory? But it can get correct result.</p>