title: Why can't I access the nth element of my decayed 2D array of strings?
body: <p>I'm messing around in C by decaying 2D arrays of strings into pointers for learning purposes.</p>
  <p>I wrote the following that constructs a 2D array of strings:</p>
  <pre><code>#include &lt;stdio.h&gt;
  
  #define ARR_SIZE 10
  #define STR_LEN 20
  
  int main() {
      // Each string in our 2D array has STR_LEN bytes of space
      char arr[ARR_SIZE][ARR_SIZE][STR_LEN];
  
      for (int i = 0; i &lt; ARR_SIZE; i++) {
          for (int j = 0; j &lt; ARR_SIZE; j++) {
              snprintf(arr[i][j], STR_LEN, &quot;%d %d&quot;, i, j);
          }
      }
  
      for (int i = 0; i &lt; ARR_SIZE; i++) {
          for (int j = 0; j &lt; ARR_SIZE; j++) {
              // Print out our string to make sure the output is good
              puts(arr[i][j]);
          }
      }
  
      // Decaying my array into a pointer
      char ***p = (char ***) arr;
  
      puts((char *) *(p + 7));
      return 0;
  }
  </code></pre>
  <p>However, when I decay my array into a pointer and then attempt to access the 8th item in my decayed array, I get a segfault. I'm a little surprised by this, given my intention was to save the strings to a 2D array on the Stack.</p>
  <p>I ran Valgrind and it highlights the following line as the problem:</p>
  <pre><code>    puts((char *) *(p + 7));
  </code></pre>
  <p>I get an &quot;Invalid read of size 1 1 warning&quot; and a &quot;Address is not stack'd, malloc'd or (recently) free'd&quot;.</p>
  <p>So the error message is telling me that I'm accessing an area of memory that isn't on the stack or heap.</p>
  <p>So clearly something is going amiss here but being new to C, I'm not quite sure what is the issue. Have I not created a 2D array of strings on the Stack as I intended to? Or is the problem with how I'm decaying my array into a <code>char ***</code> pointer?</p>