0
Why print else part not if part any one knows answer tell me
void main() { float a=1.1; if (a==1.1) printf("santosh"); else printf("find reason"); getch(); }
3 Respostas
+ 3
The issue is that you are trying to compare to floats for equality. It is likely that a floating point precision error occurs:
https://floating-point-gui.de/errors/comparison/
+ 3
If a fractional number is written without the f suffix, then it is a double type precision, so you are trying to compare two different precision classes, which naturally gives false.
Debug:
float a=1.1;
if (a==1.1f) printf("santosh");
+ 2
// Try it
if (a==(float)1.1)