# How 3 and 3.0 are equal plz explain

M

#### manish sahu

what would be the output

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

op is HI
how 3==3.0 plz Explain

D

#### david

what would be the output

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

else
{
printf("Bye");

}

op is HI
how  3==3.0 plz Explain

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

T

#### Tim Prince

manish said:
what would be the output

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

op is HI
how 3==3.0 plz Explain
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.

N

#### Nick Keighley

how  3==3.0 plz Explain

it depends on the axiomisations you choose for integers and reals

T

manish said:
what would be the output

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

op is HI
how 3==3.0 plz Explain

C compares values. The two constants have the same value when compared.

K

#### Keith Thompson

C compares values. The two constants have the same value when compared.

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.

#### Ruturaj Pansare

what would be the output

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

op is HI
how 3==3.0 plz Explain

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!