P
patleonard
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.
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.