title: If ap is a pointer, why can I refer to its values through ap[i]?
body: <pre><code>class Vektor {
  private:
      double *ap;
      int len;
  public:
      Vektor() : ap(0),len(0) { } 
      Vektor(int n): len(n) { ap = new double [n]; } 
      double&amp; front() { return ap[0]; }
      double front() const { return ap[0]; }
  };
  
  int main()
  {
      int n;
      cout &lt;&lt; "n: "; cin &gt;&gt; n;
      Vektor a(n); 
      a.front() = 5; 
      cout &lt;&lt; "a.front()=" &lt;&lt; a.front() &lt;&lt; endl;
      return 0;
  }
  </code></pre>
  
  <p>I am confused by the use of the <code>ap</code> pointer in this code. By definition of the constructor, <code>ap</code>, exempting the standard constructor, points to a memory space on the heap that contains <code>n</code> double variables. So surely, if I want to return any value for <code>front()</code>, I would have to define </p>
  
  <pre><code>double front() const { return ap*[0];}
  </code></pre>
  
  <p>and </p>
  
  <pre><code>double&amp; front() { return ap*[0];}
  </code></pre>
  
  <p>rather than the way it is defined above, right? Or is <code>double* ap</code> simply the way to declare an array <code>ap</code>?</p>