c - Why does this program gives no output for float and double datatypes? -


why program gives no output float , double datatypes. however, result when same code replaced loop??

      # include <stdio.h>        int main()       {        float x=1.1;                            while (x==1.1)        {           printf("%f\n",x);         x=x-0.1;        }        return 0;       } 

   float x=1.1;                        while (x==1.1) 

float , double variables not capable of storing exact value of 1.1, close approximation. exact value in float , double different due difference in precision.

1.1 double value. storing 1.1 double float alter value. compare double value 1.1 not quite equal , never enter condition.

for work need write 1.1f ensure working same data type everywhere. in addition i'm sure else explain why comparing floating point values exact equality bad idea.


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -