+ 1
Hi. Can someone explain to me how this works?
4 Answers
+ 4
A Union can have varius data types but hold single value of size equal to it's largest element. And all data point to same location.
You have 2 int so it size is 4bytes.
First v.a store 10 in Union.
v.b replaces 10 by 20 so now v.a and v.b both have value 20. Because all variables point to same location..
v.a and v.b both return 20 only..
Hope this clears more:
https://www.tutorialspoint.com/cprogramming/c_unions.htm
+ 2
Thanks a lot. I understand
0
You're welcome.. @Arevik Khachaturian
Edit:
It's a C question. not c++@Error