Can I do this in C++?
if (4<5<6)
cout<<"valid"<<endl;
i.e a double comparison? Since I know that I can
bool a;
a = 1+2<3+4<5>6;//etc
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.
Yes, you can do it, but it won’t be what you expect. It’s parsed as
which yields
because
4<5evaluates totruewhich is promoted to1, which yields, obviously, true.You’ll need
Also, yes, you can do
but that as well is parsed as
which will evaluate to
falsesince(1+2)<((3+4)<5)yields a boolean, which is always smaller than 6.