Just do not understand why the following two have different values. The first one has value 0, while the other has value 1
if(1/10);
if(0.1);
Just do not understand why the following two have different values. The first one has value 0, while the other has value 1
if(1/10);
if(0.1);
By default the type of 1
is int
, thus 1/10
will be rounded down to 0
which is equivalent to false
. While 0.1
has some bits set and is not 0
.
On the other hand 1.0/10
is equivalent to 0.1
.
if(condition)
Here the condition
is executed and checked with 0. If that is 0 that means false
else that means true
. 1/10 gives value 0 which is equal to 0 ( as integer/integer gives integer result) so condition failes, where as 0.1 is not equal to 0, so it is treated as true
and currespoinding statements in if
block will be executed.