title: Array allows out of bounds access in C?
body: <p>Java / C++ developer here. Trying to learn C but I am confused with memory allocation for arrays.</p>
  
  <p>What is happening here?</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;windows.h&gt;
  
  int main()
  {
      int az[3];
      az[2] = 66;
      az[8] = 5214;
  
      printf("%d\n", az[8]);
  
      system("pause");
      return 0;
  }
  </code></pre>
  
  <p><strong>Output</strong></p>
  
  <pre><code>5214
  </code></pre>
  
  <p>How can that be ? Why do I not get <strong>Out of Bounds</strong> exception or a program crash? I can I do this infinitely? What is my array's length in this case? What's the point of allocating memory via <code>malloc</code> if my arrays allow me to already put values out of bounds? This makes zero sense to me.</p>
  
  <p><a href="https://i.stack.imgur.com/wVYKW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wVYKW.png" alt="enter image description here"></a></p>