title: Why can't I access a pointer to pointer for a stack array?
body: <p>Please take a look at the following code. It tries to pass an array as a <code>char**</code> to a function:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  static void printchar(char **x)
  {
      printf("Test: %c\n", (*x)[0]);
  }
  
  int main(int argc, char *argv[])
  {
      char test[256];
      char *test2 = malloc(256);
  
      test[0] = 'B';
      test2[0] = 'A';
  
      printchar(&amp;test2);            // works
      printchar((char **) &amp;test);   // crashes because *x in printchar() has an invalid pointer
  
      free(test2);
  
      return 0;
  }
  </code></pre>
  
  <p>The fact that I can only get it to compile by explicitly casting <code>&amp;test2</code> to <code>char**</code> already hints that this code is wrong.</p>
  
  <p>Still, I'm wondering what exactly is wrong about it. I can pass a pointer to a pointer to a dynamically allocated array but I can't pass a pointer to a pointer for an array on the stack. Of course, I can easily work-around the problem by first assigning the array to a temporary variable, like so:</p>
  
  <pre><code>char test[256];
  char *tmp = test;
  test[0] = 'B';
  printchar(&amp;tmp);
  </code></pre>
  
  <p>Still, can someone explain to me why it doesn't work to cast <code>char[256]</code> to <code>char**</code> directly?</p>