title: What is the difference between square bracket arrays and pointer arrays?
body: <p>As a non-C/C++ expert I always considered square brackets and pointers arrays as equal.</p>
  
  <p>ie :</p>
  
  <pre><code>char *my_array_star;
  char my_array_square[];
  </code></pre>
  
  <p>But I noticed that when use in a structure/class they don't behave the same :</p>
  
  <pre><code>typedef struct {
     char whatever;
     char *my_array_star;
  } my_struct_star;
  
  typedef struct {
     char whatever;
     char my_array_square[];
  } my_struct_square;
  </code></pre>
  
  <p>The line below displays 16, <code>whatever</code> takes 1 byte, <code>my_array_pointer</code> takes 8 bytes. 
  Due to the padding the total structure size is 16.</p>
  
  <pre><code>printf("my_struct_star: %li\n",sizeof(my_struct_star));
  </code></pre>
  
  <p>The line below displays 1, <code>whatever</code> takes 1 byte, <code>my_array_pointer</code> isn't taken in account.</p>
  
  <pre><code>printf("my_struct_square: %li\n",sizeof(my_struct_square));
  </code></pre>
  
  <p>By playing around I noticed that square brackets are used as extra space in the structure</p>
  
  <pre><code>my_struct_square  *i=malloc(2);
  
  i-&gt;whatever='A';
  i-&gt;my_array_square[0]='B';
  </code></pre>
  
  <p>the line blow displays A:</p>
  
  <pre><code>printf("i[0]=%c\n",((char*)i)[0]);
  </code></pre>
  
  <p>the line blow displays B:</p>
  
  <pre><code>printf("i[1]=%c\n",((char*)i)[1]);
  </code></pre>
  
  <p>So I cannot say anymore that square brackets are equals to pointers. But I'd like to understand the reason of that behavior. I'm afraid of missing a key concept of that languages.</p>