title: Why am I not able to modify the contents of const int even with const_cast<int*>?
body: <pre><code>int* a = new int;
  const int y = 7;
  a = const_cast&lt;int*&gt;(&amp;y); 
  *a = 8;
  std::cout &lt;&lt; *a &lt;&lt; std::endl;
  std::cout &lt;&lt; (int)*(&amp;y) &lt;&lt; std::endl;
  </code></pre>
  
  <p>Output:</p>
  
  <p>8</p>
  
  <p>7</p>
  
  <p>Same output even with a simple cast</p>
  
  <pre><code>a = (int*)(&amp;y);
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/nmYun.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nmYun.png" alt="before modifying"></a>
  <a href="https://i.stack.imgur.com/UXxWG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UXxWG.png" alt="after modifying"></a></p>
  
  <p>If it were the RO segment of the memory, how does it even show the modification in debug mode?</p>
  
  <p><strong>EDIT:</strong>
  Since it is closed - I will just add it here</p>
  
  <p>I looked at the assembly output</p>
  
  <pre><code>std::cout &lt;&lt; (int)*(&amp;y) &lt;&lt; std::endl;
  00381CB6  push        offset std::endl&lt;char,std::char_traits&lt;char&gt; &gt; (03813C5h)  
  00381CBB  push        7  
  00381CBD  mov         ecx,dword ptr [_imp_?cout@std@@3V?$basic_ostream@DU?$char_traits@D@std@@@1@A (03900ACh)]  
  00381CC3  call        dword ptr [__imp_std::basic_ostream&lt;char,std::char_traits&lt;char&gt; &gt;::operator&lt;&lt; (03900B8h)]  
  00381CC9  mov         ecx,eax  
  00381CCB  call        dword ptr [__imp_std::basic_ostream&lt;char,std::char_traits&lt;char&gt; &gt;::operator&lt;&lt; (03900BCh)]  
  </code></pre>
  
  <p>The compiler will just replace const values at compile time. Nothing to do with RO segment as I wrongfully assumed :)</p>