# How 3 and 3.0 are equal plz explain

Discussion in 'C Programming' started by manish sahu, Aug 18, 2009.

1. ### manish sahuGuest

what would be the output

if(3==3.0)
{
printf("HI");
}
else
{
printf("Bye");
}

op is HI
how 3==3.0 plz Explain

manish sahu, Aug 18, 2009

2. ### davidGuest

It's hard to explain, try http://mathforum.org for a better answer

david, Aug 18, 2009

3. ### Tim PrinceGuest

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.

Tim Prince, Aug 18, 2009
4. ### Nick KeighleyGuest

it depends on the axiomisations you choose for integers and reals

Nick Keighley, Aug 19, 2009
5. C compares values. The two constants have the same value when compared.

6. ### Keith ThompsonGuest

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.

Keith Thompson, Aug 21, 2009
7. Joined:
Aug 16, 2017
Messages:
1