Given below is a segment of code in C
float k=0.6;
if(k==0.6)
printf("yes they are equal");
else
printf("no they are not equal");
The above code gives output "no they are not equal". I am working on Ubuntu 12.04 gcc 4.4
I was surprised and debugged the program. The answer is no because the value of K is not equal to 0.6. I single stepped the program in gdb and i found value of k as 0.600000024. Now my question is why 0.600000024 is assigned to k and why not 0.6. when I assign 0.7 the k has a value 0.69999998. Why does this happen?