title: C array index and accessing out of bounds
body: <p>So I have a program</p>
  
  <pre><code>#include "main.h"
  #import &lt;limits.h&gt;
  #import &lt;stdint.h&gt;
  
  int foo(const void *src, void *dst, uint16_t len)
  {
      uint16_t index;
      const uint8_t *srcRef = src;
      uint8_t *dstRef = dst;
  
      for(index = 0; index &lt;= len; index++)
      {
          dstRef[index] = srcRef[index];
          printf("-&gt; %d - %d\n", index, srcRef[index]);
      }
      printf("%d\n", index);
      return 0;
  }
  
  int main()
  {
      printf("max length of UInt16 is : %d\n", UINT16_MAX);
      uint8_t arrOr[55];
      uint8_t arr[55];
      arrOr[54] = 7;
      uint16_t len = 119;
      foo(arrOr, arr, len);
      return 0;
  }
  </code></pre>
  
  <p>Is it normal for a program to be able to access an array index out out bounds? (I was actually expecting it to crash)
  It can access up to 119(120 crashes it) when array length is 55. </p>
  
  <p>When it's 56, I can still only access up to 119 and 120 crashes it </p>
  
  <p>When it's 57, I can access up to 135 and 136 crashes it. </p>
  
  <p>I guess it's trying to access memory addresses given to the whole program and not just the array indexes. But what's actually happening when I change the array length to 57, that lets me access more addresses that I can't do by increasing it to 56? </p>