Unions and Structures in C | Programming in C | Difference between Union and Structure

preview_player
Показать описание
Difference between unions and structures
Let's take an example to demonstrate the difference between unions and structures:

#include tagopen stdio.h tagclose
#include tagopen conio.h tagclose
union unionJob
{
//defining a union
char name[32];
float salary;
int workerNo;
} uJob;
struct structJob
{
char name[32];
float salary;
int workerNo;
} sJob;
void main()
{
printf("size of union = %d bytes", sizeof(uJob));
printf("\nsize of structure = %d bytes", sizeof(sJob));
getch();
}

Output

size of union = 32
size of structure = 40
Рекомендации по теме
welcome to shbcf.ru