C struct print, decode this code?
- by pauliwago
I am in the process of studying for a test, and I'm trying to work through some practice problems. I've been working on this a while now..but can't figure it out. Please take a look at the code fragment:
union {
int i;
short x;
unsigned short u;
float f;
} testout;
testout.i=0xC0208000;
Before I ask the question, can someone please explain to me how the above code works?? My guess is that testout.i=0xC0208000 puts either an int, short, unsigned short, or float and puts the result in that address. (?)
The question is what prints out if we write printf("%d", testout.x)? I know we should expect digits....but I have no idea where they are getting the digits from....there is no output.
Any explanation would be greatly appreciated. Thanks!