+ 3
Basic data type
Why it is not updated to double during comparison and double can't be compared completely. so, question is why answer of below code is 1 and not 2. int x=10; double y=10.0; if(x==y){cout <<"1";}else{cout<<"2";}
2 odpowiedzi
+ 6
Variable x is implicitly casted to double during comparison. The value of x and y is compared, and found to be equal. Program prints 1.
+ 2
correct. Type casting is what I was expecting.... can't we say that double generally don't get proper comparison due to precision values unlike int....
I mean to say that double x and double y should not match with comparison sign... I used to do double comparison as below:
if(abs(x-y)<=0.0001) // This should be case instead of x==y