title: Using a pointer to traverse a dynamic allocation of classes
body: <p>In the following code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  class A
  {
  public:
      int a, b, c;
      A()
      {
          a=b=c=0;
      }
  };
  int main()
  {
      A* a=new A();
      A* b=a;
  
      for(int i = 0; i &lt; 10; i++)
      {
          a = new A();
          cout&lt;&lt;a-&gt;a&lt;&lt;endl;
          cout&lt;&lt;a-&gt;b&lt;&lt;endl;
          cout&lt;&lt;a-&gt;c&lt;&lt;endl;
      }
      for(int i = 0; i &lt; 10; i++)
      {
          cout&lt;&lt; b-&gt;a &lt;&lt;endl;
          cout&lt;&lt; b-&gt;b &lt;&lt;endl;
          cout&lt;&lt; b-&gt;c &lt;&lt;endl;
          b++;
      }
  
  }
  </code></pre>
  
  <p>I am making a quasi array using pointer a. However, when I try to read this array using b, I get garbage values. The problem is that b++ isn't incrementing b by a value equal to the size of an object of class A. How can I read my "array" of classes using b?</p>