+ 3
Can anyone solve this misunderstanding???
Question : double a= 0.1; double b=0.2; double c=0.3; If (a+b==c) Cout<<"yes"; Else Cout<<"no"; //Why no it's outputed?? //Is it because it's value is same but reference is different like variable a,b and c are different references??
7 odpowiedzi
+ 6
Yes
+ 6
Yes .. Actually I forgot to do that
+ 4
Is it reference concept .. If when it is reference and when value??
+ 3
https://code.sololearn.com/cpcn5vq99O29/?ref=app
https://code.sololearn.com/clm1vHX8oEYf/?ref=app
Just see this I have done these in C and CPP so that u can find the difference. Actually 0.1+0.2 is not equal to 0.3 since it's equal to 0.3000000000004 something.. so just check this one Prathik Shetty
+ 2
It's only a matter of values, here. The thing is that c is not initialized, that means that it holds some garbage value (or 0, I don't know about the C++ behavior about uninitialized value).
Whatever, a+b is 0.3 and c is unknown (and you will have only a few chances to have c = 0.3) so a+b != c : it outputs "no".
+ 2
Théophile c is initialized with 0.3?
+ 2
But wait... You changed your question... When I answered to it, c wasn't initialized to 0.3.