Home › Forums › C Programming › doubt on comparision operator › Reply To: doubt on comparision operator
June 12, 2007 at 5:35 pm
#3231
will
Participant
@drop2kumar wrote:
Hi
the followiing code is giving 1 as answer but answer should be 0 …becoz 0.7 is not grater than 0.7
1234 int main(){<br />float a=0.7;<br />printf("%d",(0.7>a));<br />}
Actually you are comparing the float type variable with a value which can be any thing. It can be an integer, float or any thing else. So in that case compiler does not know about the type.
Now if you explicitly mention the type of both the variables and then compare them the result would be according to your expectations. Hopefully this would clear your doubt.
1 2 3 4 5 6 7 8 | <br /> int main(){<br /> float a=0.7;<br /> float b=0.7;<br /> printf("%d",(b>a));<br /> printf("%d",(0.7>a));<br /> <br /> } |