Newbie question on unions
From: patleonard (cppman_at_ptd.net)
Date: 10/11/04
- Next message: James Aguilar: "Converting enums to pointers"
- Previous message: Steven T. Hatton: "Templated identity matrix with parameterize order?"
- Next in thread: Ron Natalie: "Re: Newbie question on unions"
- Reply: Ron Natalie: "Re: Newbie question on unions"
- Reply: Bugs_Slayer: "Re: Newbie question on unions"
- Reply: Rolf Magnus: "Re: Newbie question on unions"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 10 Oct 2004 21:04:50 -0400
The following code produces this output:
Characters: XY
Integer: 22872
Where does the integer 22872 come from?
#include <iostream.h>
int main()
{
union test_union{
short int i;
char ch[2];
} unvar;
unvar.ch[0] = 'X';
unvar.ch[1] = 'Y';
cout << "Characters: " << unvar.ch[0] << unvar.ch[1] << '\n';
cout << "Integer: " << unvar.i << '\n';
return 0;
}
It may be a stupid question, but I don't know the answer. Any response will
be helpful, thank you.
- Next message: James Aguilar: "Converting enums to pointers"
- Previous message: Steven T. Hatton: "Templated identity matrix with parameterize order?"
- Next in thread: Ron Natalie: "Re: Newbie question on unions"
- Reply: Ron Natalie: "Re: Newbie question on unions"
- Reply: Bugs_Slayer: "Re: Newbie question on unions"
- Reply: Rolf Magnus: "Re: Newbie question on unions"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|