title: What is the sizeof(struct)?
body: <pre><code>int main()
  {
    struct node
    {
      char i;
      int a;
    };
    printf("sizeof(struct node) =%d\n",sizeof(struct node));
    return 0;
  }
  </code></pre>
  
  <p>The output for this program is 8 byte. Here sizeof(int)+size(char) is not equal to 8 byte. Still, we are getting 8 byte. It is because of padding. Thats fine. But in the following program, this very concept is being violated. Why?</p>
  
  <pre><code>int main()
  {
    struct node
    {
      double i;
      int a;
    };
    printf("sizeof(struct node) =%d\n",sizeof(struct node));
    return 0;
  }
  </code></pre>
  
  <p>if sizeof(double) is 8 byte then sizeof(struct node) should be 16 byte(as per first program). But it is printing 12 byte. Why?</p>