When I compile and run the following code, x only gets printed when I initialize float x=1.5. It does not work for other values, for example, when I initialize float x=1.2 and write when(x==1.2), it does not print the value of x.
#include<stdio.h>
int main()
{
float x=1.5;
while (x==1.5)
{
printf("\n%f",x);
x-=1;
}
}
However, when I initialize float x=1.2f and write when(x==1.2f), the code runs as intended.
Also, if I declare and initialize x as double x=1.2, and write printf("\n%lf",x);, the code runs as intended.
This happens in both C and C++.