473,699 Members | 2,700 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

'==' operator for int==float

3 New Member
main()
{
int a=3;
float b=3.0;
if(a==b)
printf("3.0 is equal to 3 in c language");
else

printf("it's not\n");
}
Sep 20 '16 #1
3 1238
weaknessforcats
9,208 Recognized Expert Moderator Expert
You can't use operator== on a float. Because of float rounding, you will never be exactly equal.
Sep 21 '16 #2
narayan230979
3 New Member
thanks for reply.
u mean o/p should be :-it's not
right ?
Sep 21 '16 #3
donbock
2,426 Recognized Expert Top Contributor
The issue isn't that you can't use the == operator with floating point operands; the compiler is happy to let you do it.

The issue is that you shouldn't do it because of the reason @weaknessforcat s gave above.

The result of your comparison is unpredictable.
Sep 21 '16 #4

Sign in to post your reply or Sign up for a free account.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.