title: Memory alignment in an array of structures
body: <p>I have an array of structures defined as below:</p>
  
  <p><code>struct {
      int x;
      char y;
  } arr[10];</code></p>
  
  <p>The size of int on my machine is 4 bytes and a char is of 1 byte. I know the structures would be padded internally i.e each element of array will have a size of 8 bytes. But i want to know  whether</p>
  
  <p>1) This is because of the alignment requirement of the int-type member in the next array element or </p>
  
  <p>2) Is it because each structure should itself be aligned on a 8-byte boundary because of the requirement of natural alignment on a structure type variable.</p>
  
  <p>To make my point more clear what should be starting address of the first member of array?
  If it's an 8 byte aligned address as pointed out in the second case, this may be a problem while defining large 2-D arrays like:</p>
  
  <p>int arr[1000][1000];</p>
  
  <p>Here each element of the 2-D array (i.e each 1-D array) should be aligned on a 4000 byte boundary. The machine may not have memory hole to fulfill this memory requirement.</p>