title: How do square brackets work in C?
body: <p>I've just started with C and I'm trying to understand the basics.  Plenty of tutorials will tell you things and have you believe it without any real explanation and there are no answers on that I can find that are human readable.</p>
  
  <p>In the following:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main(int argc, char *argv[])
  {
    int *a;
  
    a = malloc(5 * sizeof(int));
  
    a[2] = 4;
  
    printf("%d\n", a[0]); // Prints 0
    printf("%d\n", a[2]); // Prints 4
  
    return 0;
  } 
  </code></pre>
  
  <p>I have not explicitly declared <code>int *a</code> as a pointer to an array, but if I allocate it some memory, I can then use <code>a</code> like I <em>had</em> declared it as an array.  Is declaring a pointer with square brackets just a shortcut for what I've done below?  Are square brackets actually doing some pointer arithmetic?</p>
  
  <p><strong>Cheeky Second question</strong></p>
  
  <p>Why is the memory address assigned to <code>a</code> and not <code>*a</code>?</p>