title: C++ const_cast does not remove the const-ness of variable
body: <p>I tried executing the following program.</p>
  
  <pre><code>#include&lt;iostream&gt;
  using namespace std;
  int main()
  {
  const int a = 0;
  cout &lt;&lt; &amp;a &lt;&lt;endl;
  int* ptr = const_cast&lt;int*&gt;(&amp;a);
  *ptr = 2;
  cout &lt;&lt; ptr &lt;&lt;endl;
  cout &lt;&lt; *ptr &lt;&lt;endl;
  cout &lt;&lt; a &lt;&lt;endl;
  return 0;
  }
  </code></pre>
  
  <p>The output was:</p>
  
  <pre><code>   0xbf92ebd8
     0xbf92ebd8
     2
     0
  </code></pre>
  
  <p>From what I know, const_cast makes <em>a</em> mutable, so that, it can be changed. The change is reflected when I display *ptr, but the change is not reflected in <em>a</em>. 
  Can anyone explain ?</p>
  
  <p>EDIT:
  Thanks for all the answers. I get it that I am observing an undefined behavior. And, I was initially confusing between <em>mutable</em> and *const_cast*.
  But then, could you tell me for what all scenarios, do we use const_cast?</p>