+ 1

Why does this happen?

Maybe because values were stored on the same memory location for members with the same data type? Correct me if I'm wrong. I'm just curious. https://code.sololearn.com/cPR5G2SrI2vQ/?ref=app

14th Jan 2020, 7:40 AM
CASOY
CASOY - avatar
1 Resposta
+ 5
Union allows you store different data types in the same memory location. But only one variable contain memory location at a given time. In your program, v. first, and v.second points to same memory location.. And because of same same type, you get last modified value to both of them. If it any other datatype like float, you get a converted garbage value..
14th Jan 2020, 8:11 AM
Jayakrishna 🇮🇳