dimanche 20 septembre 2015

Why does >= operator work as > operator in C when compared with 0.9

I was working with C and tried this :-

#include<stdio.h>
int main()
{
     float b=0.8,a=0.6;
     if(a&&b>=0.8)
     printf("\nclass")  ;
     else
     printf("\nb");
     return 0;
}

And the output came :-

class

But when I changed the value of b to 0.9 and expression in if to a&&b>=0.9 :-

#include<stdio.h>
int main()
{
     float b=0.9,a=0.6;
     if(a&&b>=0.9)
     printf("\nclass")  ;
     else
     printf("\nb");
     return 0;
}

then output was:-

b

Can anyone explain why >= operator started to act as > operator when the value of b was 0.9 ?

Thanks in advance.

Something to add as some guys think I am wasting their time :- I also tried to debug it as :-

    #include<stdio.h>
int main()
{
float b=0.9,a=0.6;
printf(" int a   -   %d\n", (int)a);
printf("int b -    %d\n", (int)b);
printf("a&&b  -   %d\n", a&&b);
printf("b>=0.9  -  %d\n", b>=0.9);
if(a&&b>=0.9)
printf("\nclass");
else
printf("\nb");
return 0;   
}

Now the O/p was :-

int a   -   0
int b -    0
a&&b  -   1
b>=0.9  -  0

Now please that "Precedence Guy" tell me what order of precedence would be followed in a single >= operator.

Aucun commentaire:

Enregistrer un commentaire