If your C textbook doesn't explain how 3==3.0 is equivalent to
(double)3 == 3.0
you need a better textbook.
I would prefer that a C textbook would explain questions such as when
such casts are exact, but that preference does go beyond reality.
Well, they have different types. Specifically, 3 is of type int, and
3.0 is of type double. The standard specifies rules for converting
operands of "==" to a common type. In this case, the value 3 is
converted from int to double, and the result if this conversion is
compared to 3.0. Converting the int value 3 to double will almost
certainly yield the value 3.0, though I don't think the standard
quite guarantees it.
Well it must be int something say x=3 and something float sat y=3.0 In C when there is an operation between an int and a float ,the int is converted into float.In this example 3 is converted to 3.0 and then the comparison is made.Hence 3 == 3.0.Hope this works!
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.