title: How is memory alignment done usually?
body: <p>Have a look at these 2 cases: </p>
  
  <pre><code>class A {
      public:
      int a;
  
      A () { a = 10;}
      void foo () {std::cout &lt;&lt; "a = " &lt;&lt; a &lt;&lt; std::endl;}
  };
  </code></pre>
  
  <p>Here sizeof(A) gives 4 bytes, which makes sense.</p>
  
  <pre><code>class A {
      public:
      int a;
  
      A () { a = 10;}
      virtual void foo () {std::cout &lt;&lt; "a = " &lt;&lt; a &lt;&lt; std::endl;}
  };
  </code></pre>
  
  <p>Here sizeof(A) gives 16 bytes as opposed to 12 bytes (4 + 8 for pointer).</p>
  
  <p>Is there any explanation in terms of memory alignment for this ?</p>