Can I compare and add a floating-point number to an integer in C?

前端 未结 9 1296
余生分开走
余生分开走 2020-12-14 02:50

Can I compare a floating-point number to an integer?

Will the float compare to integers in code?

float f;     // f has a saved predetermined floating         


        
9条回答
  •  被撕碎了的回忆
    2020-12-14 03:16

    Yes, and sometimes it'll do exactly what you expect.

    As the others have pointed out, comparing, eg, 1.0 == 1 will work out, because the integer 1 is type cast to double (not float) before the comparison.

    However, other comparisons may not.

提交回复
热议问题