title: Declaring a Global Multidimensional Array in C
body: <p>So, I'm trying to declare a 3-dimensional integer array globally so that it can be used by two separate functions.</p>
  
  <p>Initially, I had tried this (<code>solns</code> being the name of the 3D array):</p>
  
  <pre><code>static int*** solns;
  </code></pre>
  
  <p>But while the triple pointer <code>solns</code> does persist between functions, the information I place inside of it does not.  This gives me a segfault when the second function tries to access data that the first function placed in <code>solns</code>.</p>
  
  <p>How should I declare this such that the information inside remains?  I've tried</p>
  
  <pre><code>static int solns[][][];
  </code></pre>
  
  <p>among other things, but gcc doesn't like anything else I try.</p>
  
  <p>EDIT: This snippet of code from function 1 places data into the array:</p>
  
  <pre><code>solns[k] = realloc(solns[k],sizeof(solns[k])/sizeof(int*)+sizeof(int*));
  solns[k][l] = realloc(solns[k][l],sizeof(int)*4*sC);
      for(i=0;i&lt;sC*4;i++)
      {
          solns[k][l][i] = row[i];
      }
      l++;
  </code></pre>
  
  <p>And this snippet is where function 2 tries to read that data:</p>
  
  <pre><code>if(solns[i][j][m*4+1]!=solns[i+1][n][m*4+2])
      break;
  </code></pre>
  
  <p>But <code>solns[i]</code> is a null pointer at that point because the data pointed to by <code>solns</code> doesn't carry over.</p>