#include <stdio.h>
main()
{
int iInteger;
char cChar1, cChar2;
typedef union stuff
{
int iInt;
char cChar[2];
} uSTUFF;
uSTUFF uStuff;
iInteger = OXFFFF;
cChar1 = 'A'; /* 0X41 in ASCII Char Set */
cChar2 = 'B'; /* 0X42 in ASCII Char Set */
printf ("\nstuff(): raw iInteger value is %x",
iInteger);
uStuff.iInt = iInteger;
printf ("\nstuff(): uStuff integer value is %x",
uStuff.iInt);
uStuff.cChar [0] = cChar1;
printf ("\nstuff(): uStuff integer value is %x",
uStuff.iInt);
uStuff.cChar[1] = cChar2;
printf ("\nstuff(): uStuff integer value is %x",
uStuff.iInt);
}
Output from above stuff() program:
stuff(): raw iInteger value is ffff
stuff(): uStuff integer value is ffff
stuff(): uStuff integer value is ff41
stuff(): uStuff integer value is 4241