when I use:
if( a>=0 && a<100 && b>=0 && b<200 )
everything works fine but if I use:
if( 0<=a<100 && 0<=b<200 )
my program crashes. a and b = floats. Can somebody please tell me what’s the difference?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
0<=a<100is actually(0<=a)<100. Since(0<=a)is a boolean, its value is always either 0 or 1 (true or false), therefore the expression becomes0<100(or1<100), which is always true.Since you are sort-of indexing an array with
aandb, the wrong bounds check leads to, well, an out-of-bounds access, which crashes your application.