This repository has been archived on 2023-10-26. You can view files and clone it, but cannot push or open issues or pull requests.
VSMechatronics/LC19/union.c

31 lines
719 B
C
Raw Normal View History

2022-04-07 15:58:01 +00:00
#include <stdio.h>
#include <stdlib.h>
union number{
double d;
float f;
long l;
int i;
short s;
unsigned char c[8];
};
int main(void)
{
int my_i;
union number mynum;
printf ("\nPlease enter a number ");
scanf("%d",&my_i);
printf ("\nThe bytes making up your number %d are ",my_i);
mynum.i = my_i;
printf ("%d %d %d %d %d %d %d %d ",mynum.c[0],mynum.c[1],mynum.c[2],mynum.c[3],mynum.c[4],mynum.c[5],mynum.c[6],mynum.c[7]);
printf ("\nSize of double id %d ",sizeof(double));
printf ("\nSize of float id %d ",sizeof(float));
printf ("\nSize of long id %d ",sizeof(long));
printf ("\nSize of int id %d ",sizeof(int));
printf ("\nSize of short id %d ",sizeof(short));
return 0;
}