title: C - Array initialization using strlen making array wrong size
body: <p>I'm experiencing an unexpected interaction with char array initialization.</p>
  
  <p><strong>When initializing a char[] with a size of strlen( char parameter[] ), the newly initialized char[] is too big.  I am not sure what is causing this.</strong></p>
  
  <pre><code>int main(void)
  {
      char myString[] = { " " };
      foo( myString );
  }    
  
  
  int foo( char str[] )
  {
      char testString[ strlen( str ) ];
      printf( "Length of testString: %lu\n", strlen( testString ) );
      return 0;
  }
  </code></pre>
  
  <p>When I run foo, the output is </p>
  
  <pre><code>Length of testString: 6 
  </code></pre>
  
  <p>when I am expecting it to be 1.</p>
  
  <hr>
  
  <p>Even stranger is when I add a print statement to foo before the initialization of testString, the output seems to magically fix itself:</p>
  
  <pre><code>int foo( char str[] )
  {
      printf( "Length of str: %lu\n", strlen( str ) );
      char testString[ strlen( str ) ];
      printf( "Length of testString: %lu\n", strlen( testString ) );
      return 0;
  }
  </code></pre>
  
  <p>foo now prints</p>
  
  <pre><code>Length of str: 1
  Length of testString: 1
  </code></pre>
  
  <hr>
  
  <p>I have a feeling that it has something to do with the way char[] are passed into functions, or perhaps an unexpected behavior of strlen, but I really have no idea.</p>
  
  <p>Any help is appreciated.</p>