title: Dynamic and static char array
body: <p>Here are the codes of a program:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  char * cloning(char * q){
      char s[strlen(q)];
      int i;
      for(i = 0; i &lt; strlen(q); i++)
          s[i] = q[i];
      return s;
  }
  
  int main(){
      char q[] = "hello";
      char *s = cloning(q);
      return 0;
  }
  </code></pre>
  
  <p>After the compilation a warning appears, so I changed the returned value like this:</p>
  
  <pre><code>char *b = s;
  return b;
  </code></pre>
  
  <p>In this way the warning can be solved. However I found that inside the function cloning(), sizeof(s) is 5, but strlen(s) is 7. And if I change char s[strlen(q)] simply to char s[5], the output is still incorrect. Can anybody explain this problem to me? Thank you very much.</p>