Write a
program to verify the difference between union and structure:
#include <stdio.h>
union job
{
//defining a
union
char
name[32];
float salary;
int
worker_no;
}u;
struct job1
{
char
name[32];
float salary;
int worker_no;
}s;
int main()
{
printf("size
of union = %d",);
// sizeof(u) - This will be equal to the
size of the largest member in the union
printf("
\nsize of structure = %d", sizeof(s));
// sizeof(s)
- This will be equal to the sum of sizes of all members of the structure
return 0;
}
OUTPUT:
Size of union = 32
Size of structure = 38