Why i got answer in a int vale like 1093140480 ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why i got answer in a int vale like 1093140480 ?

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

24th May 2019, 10:38 AM
Gajendra Parmar
Gajendra Parmar - avatar
4 Answers
+ 2
It means it take rendom value in my case value of c is 10.5 float value then it print value of a which is int so display such value 1093140480
24th May 2019, 11:08 AM
Gajendra Parmar
Gajendra Parmar - avatar
+ 1
Because it's an unión and not a structure. Example : union u { int a; int b; } union u s; s.a = 10; //a = 10 and b = 10 s.b = 11; //a = 11 and b = 11 So it's the same in your case. a contains the value of a float.
24th May 2019, 10:54 AM
Théophile
Théophile - avatar
+ 1
But why i got this value 1093140480
24th May 2019, 10:57 AM
Gajendra Parmar
Gajendra Parmar - avatar
+ 1
Let see in binary with an example : union u { char a; char b; } union u s; s.a = 1; //s = 0000 0001 so s.b = 0000 0001 s.a = 2 //s = 0000 0010 so s.b = 0000 0010 s.b = 10 //s = 0000 1010 so s.a = 0000 1010 In your case, the integer à contains the value of the float c.
24th May 2019, 11:01 AM
Théophile
Théophile - avatar