+ 2
Why this C code prints different output in different runs?
Shouldn't it just print 5? Cuz it converts int to double and loses the decimal numbers https://code.sololearn.com/clF1dG346S32/?ref=app
2 Réponses
+ 6
Rishi
Everytime you are getting garbage value because of incompatible type of int and double.
So if you want to print only 5 then use %.f
printf("%.f", a);
Or you have to cast with int:
printf("%d", (int) a);
+ 1
A͢J but why does it produce a garbage value? What does it do with the a then? Won't it just misinterpret the 'a' and produce some wrong value, but related to a? (So that the output won't change everytime)