C Programming Puzzle: Code Output

1
Puzzle Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int c;
float a=0.41;
c=a*100;
printf("%d",c);
getch();
}
The output of the above code is 40 not 41. Why?
(Solution in comments)

Get the best of Durofy in your inbox

Share.

About Author

1 Comment

  1. Solution: Compiler never stores an exact float value in the memory. An approximate value of the float is stored. Example in above case a value would be like 0.408235 or so which is approx to 0.41. When this value is multiplied by 100 and stored in an int it becomes 40, which is the output.