By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,336 Members | 2,307 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,336 IT Pros & Developers. It's quick & easy.

'==' operator for int==float

P: 3
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
Share this Question
Share on Google+
3 Replies


weaknessforcats
Expert Mod 5K+
P: 9,197
You can't use operator== on a float. Because of float rounding, you will never be exactly equal.
Sep 21 '16 #2

P: 3
thanks for reply.
u mean o/p should be :-it's not
right ?
Sep 21 '16 #3

Expert 100+
P: 2,400
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 @weaknessforcats gave above.

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

Post your reply

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