title: Pointers dereferencing differences between [] and *
body: <p>I have come across an opinion that in case we have a pointer to a pointer, we can dereference it via <code>[][]</code> in case the allocated memory is adjacent. In case its not, only dereferencing via pointers arithmetic can be used. But I cannot quite reproduce that situation, i.e. here is an example code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  #define ITEMS_NO    3
  #define LETTERS_NO  4
  
  int main(void)
  {
      char* theArray[ITEMS_NO];
      char* dummyArr[ITEMS_NO];
  
      for (int i = 0; i &lt; ITEMS_NO; ++i)
      {
          theArray[i] = malloc(LETTERS_NO);
          dummyArr[i] = malloc(LETTERS_NO); // make sure mem is not adjecent
  
          for (int k = 0; k &lt; LETTERS_NO - 1; ++k)
          {
              theArray[i][k] = '0' + i;
              dummyArr[i][k] = 'z';
          }
  
          theArray[i][LETTERS_NO - 1] = 0;
          dummyArr[i][LETTERS_NO - 1] = 0;
      }
  
      for (int i = 0; i &lt; ITEMS_NO; ++i)
      {
          printf("item by square bracket %i = %c \n", i, theArray[i][1]);
          printf("item by ptr %i = %c \n", i, *((*(theArray + i)) + 1));
          free(theArray[i]);
          free(dummyArr[i]);
      }
  }
  </code></pre>
  
  <p>In this example i allocate the <code>dummyArr</code> in order to make sure that the allocated memory for the <code>theArray</code> is not adjacentnext to each other. Both <code>printf</code> calls give the same results. Am I not getting something here or do both dereferencing methods work exactly the same way?</p>