【发布时间】:2012-10-19 11:05:38
【问题描述】:
可能重复:
Double comparison
int x=-1;
if(0<=x<=9)
std::cout<< "Without Logical operator";
if (0<=x && x<=9)
std::cout<< "With Logical operator";
我知道第二个if 它工作正常。
在第一个 if 条件中发生了什么。它进入第一个if 除了x 是-1
以及为什么编译器在使用(0<=x<=9) 时没有给出error
【问题讨论】:
-
if((0<=x)<=9)->if(false<=9)->if(0<=9) -
类似于
(0 * x * 9)。 -
我看不出编译器有任何抱怨的理由……它是一个有效的语法
标签: c++ c comparison operators