Program to find number of bytes allocated to structure and union
#include <stdio.h>
union unionJob
{
//defining a union
char name[3];
float salary;
int workerNo;
} uJob;
struct structJob
{
// defining a structure
char name[3];
float salary;
int workerNo;
} sJob;
int main()
{
printf("size of union = %ld bytes", sizeof(uJob));
printf("\nsize of structure = %ld bytes", sizeof(sJob));
return 0;
}
output:
#include <stdio.h>
union unionJob
{
//defining a union
char name[3];
float salary;
int workerNo;
} uJob;
struct structJob
{
// defining a structure
char name[3];
float salary;
int workerNo;
} sJob;
int main()
{
printf("size of union = %ld bytes", sizeof(uJob));
printf("\nsize of structure = %ld bytes", sizeof(sJob));
return 0;
}
output:
No comments:
Post a Comment