oh hey, Don't unions only hold one member at a time? Thus only data.d would output, and the others would give an error or throw random numbers at you.
Je pense...
Ok One more funny one
Consider the following code:
What is the output it generates?Code:union Data { public: unsigned short a; unsigned int b; unsigned char c; unsigned long long d; }; void main () { Data data; data.a = 32123; data.b = 53129876; data.c = 128; data.d = 908292342362633; cout << "a=" << data.a << endl; cout << "b=" << data.b << endl; cout << "c=" << (unsigned int)data.c << endl; cout << "d=" << data.d << endl; system("pause"); }
oh hey, Don't unions only hold one member at a time? Thus only data.d would output, and the others would give an error or throw random numbers at you.
Je pense...
Darn, fail double post
Last edited by zeco; 09-29-2009 at 07:13 PM.
Zeco: <!-- Not quite, but I can see why you remembered it that way... with unions they live in the same memory space. Does that give any insight? -->
i know d would be the value you assigned to it because you assigned it last. but have on idea what the other ones would be
Ah we-a blaze the fyah, make it bun dem!
Wow. this is going to be wierd. All sharing the same memory space huh? BTW I've never seen anyone write declare a long long before :P
EDIT: I just read what HD wrote so the opposite of this, because the last assignment would overide. And Oh god. It's in binary so You would have convert 908292342362633 into binary then map out each part. Hell I'm not doing this conversion I'll use the internet:
0000 0011 0011 1010 0001 0110 [0100 1010 0110 1011 [0011 0010 [0000 1001]]]
110011101000010110 01001010011010110011001000001001
Ok. a Char is a Byte
short is 2 Bytes or Word
int is 32 bits or 4 Bytes or DWord
long is 64 bits or QWORD
long long is 256 bits or 4 QWords!
This number fills atleast 7 Bytes so what's printed is:
12809
4877106
9
908292342362633
I think... >_<
Last edited by why06; 09-30-2009 at 01:14 PM.
"Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."- Dwight D. Eisenhower
long long is just making sure it's 64 bit
and yes both HD & Why are on the right track.. so whip out your windows calculator and get to it
BTW: BA this isn't funny at all unless you find the idea of inflicting pain on others funny o_O
"Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."- Dwight D. Eisenhower
Hell_Demon (09-30-2009)
QFT :P
Calculator eh? silly hex haxxed my answer!
908292342362633 is 33A164A6B3209 in hex
short is 2 bytes, so we take the last 4 numbers of the hex(since 1 byte can be 255 max, which is FF in hex) =)
3209(hex) = 12809(decimal)
so:
a=12809
b is an int which is 4 bytes, so the last 8 numbers from the hex (4A6B3209)
4A6B3209(hex) = 1248539145(decimal)
a=12809
b=1248539145
c is a char, which is 1 byte so the last 2 from the hex
09(hex) = 9(decimal)
a=12809
b=1248539145
c=9
d stays the same
a=12809
b=1248539145
c=9
d=908292342362633
i win =)
Ah we-a blaze the fyah, make it bun dem!