Login or Sign Up
Logging in...
Remember me
Log in
Or
Sign Up
Forgot password or user name?
Log in with
Search in titles only
Search in C only
Search
Advanced Search
Forums
BYTES
Product Launch
Updates
Developer Toolkit
Member List
Calendar
Today's Posts
Home
Forum
Topic
C
'==' operator for int==float
'==' operator for int==float
Collapse
X
Collapse
Posts
Latest Activity
Photos
Page
of
1
Filter
Time
All Time
Today
Last Week
Last Month
Show
All
Discussions only
Photos only
Videos only
Links only
Polls only
Events only
Filtered by:
Clear All
new posts
Previous
template
Next
narayan230979
New Member
Join Date:
Sep 2016
Posts:
3
#1
'==' operator for int==float
Sep 20 '16, 07:54 PM
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");
}
weaknessforcats
Recognized Expert
Expert
Join Date:
Mar 2007
Posts:
9214
#2
Sep 21 '16, 12:20 AM
You can't use operator== on a float. Because of float rounding, you will never be exactly equal.
Comment
Post
Cancel
narayan230979
New Member
Join Date:
Sep 2016
Posts:
3
#3
Sep 21 '16, 03:06 PM
thanks for reply.
u mean o/p should be :-it's not
right ?
Comment
Post
Cancel
donbock
Recognized Expert
Top Contributor
Join Date:
Mar 2008
Posts:
2427
#4
Sep 21 '16, 07:54 PM
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.
Comment
Post
Cancel
Previous
template
Next
Working...
OK
OK
Cancel
👍
👎
☕
Comment