title: Why does my dynamic array work without being resized?
body: <p>I'm working on dynamic arrays for my c++ course, but I'm confused about the behavior of my dynamic arrays.  For example, if I run this code:</p>
  <pre><code>int* myDynamicArr = new int[3];
  
  for (int i = 0; i &lt; 10; i++)
  {
      myDynamicArr[i] = i + 1;
      cout &lt;&lt; myDynamicArr[i] &lt;&lt; endl;
  }
  </code></pre>
  <p>I would expect it to not work since I only declared it as size 3.  But when I run it, it prints out 0-9.  Same thing if I do this:</p>
  <pre><code>char* myCharArr = new char[2];
  strcpy(myCharArr, &quot;ThisIsALongString&quot;);
  cout &lt;&lt; myCharArr;
  </code></pre>
  <p>It prints the full string even though it seems like it should fail.  Can anyone explain what I'm doing wrong here?  Thanks!</p>