title: class variables - alignment
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/14352373/classes-store-data-members-in-sequential-memory">Classes store data members in sequential memory?</a>  </p>
  </blockquote>
  
  
  
  <p>Just wanted to ask why the following is correct:</p>
  
  <pre><code>template&lt;class T&gt;
  class Vec3 {
  public:
    // values
    T x,y,z;
  
    // returns i-th komponent (i=0,1,2) (RHS array operator)
    const T operator[] (unsigned int i) const {
      return *(&amp;x+i);
    }
  }
  </code></pre>
  
  <p>or in other words: Why is it always guaranteed that x, y and z are always sizeof(T) units apart in memory. Can't there ever be fragmentation holes in between two of those varibles, thus letting this operator return a false value?</p>