title: Behavior of const auto pointers in C++
body: <p><a href="https://stackoverflow.com/a/5073644/1391081">This answer</a> claims that a const auto pointer behaves the same as a const 'regular' (i.e., non-auto) pointer, which is what I would expect.</p>
  <p>However, the following code compiles and outputs <code>100</code>:</p>
  <pre><code>int n{ 99 };
  const auto nPtr = &amp;n;
  ++(*nPtr);
  std::cout &lt;&lt; n &lt;&lt; '\n';
  </code></pre>
  <p>To dig a little deeper, I checked the types of all 4 kinds of pointers and this is the result I got:</p>
  <p><em>Code</em></p>
  <pre><code>int n{ 99 };
  
  int* intPtr = &amp;n;
  const int* intConstPtr = &amp;n;
  
  auto autoPtr = &amp;n;
  const auto autoConstPtr = &amp;n;
  
  std::cout &lt;&lt; &quot;intPtr: &quot; &lt;&lt; typeid(intPtr).name() &lt;&lt; '\n';
  std::cout &lt;&lt; &quot;intConstPtr: &quot; &lt;&lt; typeid(intConstPtr).name() &lt;&lt; '\n';
  
  std::cout &lt;&lt; &quot;autoPtr: &quot; &lt;&lt; typeid(autoPtr).name() &lt;&lt; '\n';
  std::cout &lt;&lt; &quot;autoConstPtr: &quot; &lt;&lt; typeid(autoConstPtr).name() &lt;&lt; '\n';
  </code></pre>
  <p><em>Output</em></p>
  <blockquote>
  <p>intPtr: int * __ptr64</p>
  <p>intConstPtr: int const * __ptr64</p>
  <p>autoPtr: int * __ptr64</p>
  <p>autoConstPtr: int * __ptr64</p>
  </blockquote>
  <p>So the compiler seems to be completely ignoring the const keyword with the auto pointer. Does anyone know why this is?</p>