title: about "int const *p" and "const int *p "
body: <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  int main(int argc, char* argv[])
  {
      int i1 = 0;
      int i2 = 10;
  
      const int *p = &amp;i1;
      int const *p2 = &amp;i1;
      const int const *p3 = &amp;i1;
  
      p = &amp;i2;
      p2 = &amp;i2;
      p3 = &amp;i2;
  
      cout &lt;&lt; *p &lt;&lt; endl
          &lt;&lt; *p2 &lt;&lt;endl
          &lt;&lt; *p3 &lt;&lt;endl;
      return 0;
  }
  </code></pre>
  
  <p>The code can be compiled with both VC6.0 and VC2010.
  But I have questions as blow:</p>
  
  <blockquote>
    <p>const int *p = &i1;  </p>
  </blockquote>
  
  <p>It means what the "p" points can not be modified,but p can not be modified,am I right?
  so </p>
  
  <blockquote>
    <p>p = &i2;</p>
  </blockquote>
  
  <p>this line can be complied,yes?</p>
  
  <p>This line:</p>
  
  <pre><code>int const *p2 = &amp;i1;
  </code></pre>
  
  <p>In my mind,this means p2 can not be modified while what p2 points can be changed, am i right?
  Why the </p>
  
  <blockquote>
    <p>p2 = &i2;</p>
  </blockquote>
  
  <p>can be compiled?</p>
  
  <p>About this line:    </p>
  
  <blockquote>
    <p>const int const *p3 = &i1;</p>
    
    <p>p3 = &i2;</p>
  </blockquote>
  
  <p>Oh,god... I am crazy. I have no idea why this line can be compiled with no error...
  Can any body help me?</p>
  
  <p>Another code which confused me is here:</p>
  
  <pre><code>class Coo2    
  {      
   public:     
  
   Coo2() : p(new int(0)) {}    
  
   ~Coo2() {delete p;}    
  
  
      int const * getP() const   
      {      
           *p = 1;         
           return this-&gt;p;      
      }      
  
   private:    
        int* p;    
  };   
  </code></pre>
  
  <p>why this code can be compiled?
  In </p>
  
  <blockquote>
    <p>int const * getP() const</p>
  </blockquote>
  
  <p>I have change the value or *p !</p>