title: Class members memory allocation
body: <p>My question is mostly theoretical. Suppose we have a class</p>
  
  <pre><code>class A{
  private:
      int * a;
      int b;
  private:
      A(){
        a = new int[100];
        b = 100;
      }
     ~A(){
        delete [] a;
      }
  }
  </code></pre>
  
  <p>As far as I know if we create object of type A dynamically (<code>A * a = new A()</code>) the memory for this object will allocate in heap and if I use (<code>A a</code>) it will be created on stack <code>(A a)</code>. In the case when object is created on stack memory for variable <code>a</code> will allocated on heap and in case when we allocated object on heap memory for object <code>b</code> will be allocated on stack. First question for me to be sure: am I right?</p>
  
  <p>And second question would it be more efficient to store all members of class in heap memory or stack memory eg?</p>
  
  <pre><code>class A{
      private:
          int * a;
          int * b;
      private:
          A(){
            a = new int[100];
            b = new int(100);
          }
         ~A(){
            delete [] a;
            delete b;
          }
      }
  </code></pre>
  
  <p>When I said efficient I mean that all data about class member will be storing near each other in memory in heap or stack (actually I'm not sure that is correct that they will be storing near each other).</p>