Size of the structure is defined based on multiplies of bigger data type member in the structure.
Example: If a structure contains integer, char, short data type, then size of the Structure will be multiples of size of Integer.
The following code snippet will explain the size of Structure.
================================================
#include
struct Test1
{
int a;
char b;
int c;
};
struct Test2
{
char a;
int b;
char c;
};
struct Test3
{
char a;
char b;
int c;
};
struct Test4
{
int c;
char a;
char b;
};
int main()
{
struct Test1 t1;
printf("%d\n",sizeof(t1));
struct Test2 t2;
printf("%d\n",sizeof(t2));
struct Test3 t3;
printf("%d\n",sizeof(t3));
struct Test4 t4;
printf("%d\n",sizeof(t4));
return 0;
}
================================================
Output:
12
12
8
8