Why float value cannot be used id case and switch?

1 answer

Answer

1209705

2026-08-05 11:50

+ Follow

It is by design.

Speaking of floating-point values, please remember that they are never accurate, so be careful. Example:

wrong: if (f==4.1) printf ("Equals to 4.1");

good: if (fabs (f-4.1)<0.0000001) printf ("Equals to 4.1");

ReportLike(0ShareFavorite

Copyright © 2026 eLLeNow.com All Rights Reserved.