title: Does a const variable store the value in the variable?
body: <p>I was messing around in C++ and wrote this code</p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;iostream&gt;
  
  int main() {
      const int x = 10;
      const int* ptr = &amp;x;
  
      *((int*)ptr) = 11;
  
      std::cout &lt;&lt; "ptr -&gt; " &lt;&lt; ptr &lt;&lt; " -&gt; " &lt;&lt; *((int*)ptr) &lt;&lt; std::endl;
      std::cout &lt;&lt; "x -&gt;   " &lt;&lt; &amp;x &lt;&lt; " -&gt; " &lt;&lt; x &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>Interestingly, the output in the console is:</p>
  
  <pre><code>ptr -&gt; 00CFF77C -&gt; 11
  x -&gt;   00CFF77C -&gt; 10
  </code></pre>
  
  <p>I checked the value at the memory address of <code>ptr</code> and the value is <code>11</code>, so does this imply that <code>const</code> variables store the value in them, and not in memory? And if this were the case, why have a memory address storing the value?</p>