Can we use floating variables in if statements in C?
- December 5, 2020
- Posted by: Riddhi Dhandha
- Category: C Programming Langauge at TCCI
Yes, we can use floating variable in if statement but you have to be very careful while initialising the condition C Language.
Comparisons between floating-point values (including comparisons with zero) are easily sent “off” by truncation/rounding errors.
Yes. You can use. But a direct comparison will never result in a true condition.
Remember that floating point values are hardly precise. So what you can do is along with the float value you are comparing, declare another value that serves as an upper and lower bound to your value,
Float a=6.7, b=5.8;
If (a==1) // this will be wrong in this case as condition will never be true
To do this correctly you have to write like this
TCCI coaching institute teach all programming language to all school boards, all university, all branch students and any non-IT person.
Join us @ TCCI.
Call us @ 9825618292
Visit us @ http://tccicomputercoaching.com/