+ 1

Hi. Can someone explain to me how this works?

https://www.sololearn.com/post/1518481/?ref=app

8th Feb 2022, 11:31 AM
Arevik Khachaturian
Arevik Khachaturian - avatar
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
8th Feb 2022, 11:41 AM
Jayakrishna 🇼🇳
+ 2
Thanks a lot. I understand
8th Feb 2022, 12:03 PM
Arevik Khachaturian
Arevik Khachaturian - avatar
0
You're welcome.. @Arevik Khachaturian Edit: It's a C question. not c++@Error
8th Feb 2022, 12:11 PM
Jayakrishna 🇼🇳