title: C++ Stack around the variable x was corrupted
body: <p>I am new to C++. I am learning some basics.
  I tried the below program and got a run time error Stack around the variable x was corrupted. </p>
  
  <pre><code>int x = 56;
  int *ptr = &amp;x;
  ptr[1]=8;
  cout &lt;&lt; *ptr &lt;&lt; endl;
  </code></pre>
  
  <p>But if i update the index in line 3 to 0, say ptr[0] = 8, I am not getting any run time error and the console shows 8 as the output.</p>
  
  <p>I assume 2 digits in the integer variable x and thought pointer index will have 0 and 1 as valid values. Why ptr[1] is causing run tume error where as ptr[2], ptr[3] does not cause any run times error and simply shows 56 as o/p.</p>
  
  <p>Can any one help me to understand what is really going on here. May be a better tutorial site as an add on would help me to understand more on this subject.</p>