struct and union in C
These both declare same and uses are almost same;
just the difference when use
struct then need to declare with ‘struct’ keyword
struct student
{
int roll;
float age;
};
when use union then declare as
union student
{
int roll;
float age;
};
There is also a strong difference between struct and union
struct size measure by sum of all the used datatypes in struct;
like
struct student
{
int roll;
float age;
};
for this student struct datatype size is 6 bytes i.e ( 2 + 4);
union student
{
int roll;
float age;
};
where union size measure by the largest data size like in this example
student union data types size is 4 bytes.