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

前端 未结 9 1272
余生分开走
余生分开走 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:27

    Yes, you can compare them, you can do math on them without terribly much regard for which is which, in most cases. But only most. The big bugaboo is that you can check for f etc. but should not check for f==i. An integer and a float that 'should' be identical in value are not necessarily identical.

提交回复
热议问题