+ 1

Can anybody explain the output of code?

https://code.sololearn.com/ckzp3l29mK7S/?ref=app

9th May 2019, 3:37 PM
Bhakta
Bhakta - avatar
2 Respostas
+ 3
Union stores only one element at a time, so all access the same memory spot. Size of the largest type, here int. The last change was to 300. Since a and b are char it shows 44 instead of 300, because chars repeat every 256 places so to say (it,s actually because of bit representation and char being only 1 byte = 8 bit large, i.e. 2^8=256 possible values) If you replace %d by %c, you will se the corresponding character.
9th May 2019, 3:50 PM
Matthias
Matthias - avatar
+ 4
union stores its members in same memory location so when you change one of its members others change too
9th May 2019, 3:59 PM
Mert Yazıcı
Mert Yazıcı - avatar