-4
#include <stdio.h>

struct temp{
 char b1; 
 double a; 
 int f;
};
int main()
{
  struct temp temp1;
  int size = 0;

  size = sizeof(temp1);
}

why size value is 24 instead of 20?... In 32 bit machine.

Advance Thanks...

PraveenG
  • 7
  • 1

1 Answers1

0
struct temp{
 char b1;  // 1 byte + 7 bytes padding
 double a; // 8 bytes
 int f;    // 4 bytes + 4 bytes padding
};

This is because of member padding :)

Saurav Sahu
  • 13,038
  • 6
  • 64
  • 79