title: Dynamic memory allocation in C++ language
body: <p>I want to allocate space for char array (string) in C++. When I allocate memory for 10 chars, I can also assign more characters to the char array. When I print it, it gives some of the additionally assigned characters from the array.</p>
  <pre><code>#include &lt;string.h&gt;
  
  using namespace std;
  
  int main()
  {
      char *name = new char[10];
  
      strcpy(name, &quot;MoreThanTenCharacters&quot;);
  
      cout &lt;&lt; name &lt;&lt; endl;
  }
  
  </code></pre>
  <p>Although the allocated memory is for 10 characters, I can assign more. Printing gives exactly the same value. What is the logic behind it?</p>