C Programming - Anomaly behaviour of while loop for float condition [duplicate]
问题 This question already has answers here : Float comparison gives different results (7 answers) Closed 2 years ago . I wrote the following code: #include <stdio.h> int main () { float x = 1.1; printf("%s\n", "Hello!"); while (x == 1.1) { printf("%s\n", "Hey there!"); printf("%f\n", x); x = x - 0.1; } printf("%s\n", "Bye!"); return 0; } However the output was (which I assume was not expected): aps120797@XENON-PC:/mnt/d/Codes/LetUsC$ gcc C04Ag.c aps120797@XENON-PC:/mnt/d/Codes/LetUsC$ ./a.out