C++ 带有两个关系运算符的单个变量如何在内部工作

C++ 带有两个关系运算符的单个变量如何在内部工作,c++,logical-operators,boolean-expression,relational-operators,C++,Logical Operators,Boolean Expression,Relational Operators,如果需要组合布尔表达式,我们通常使用逻辑运算符。我想知道表达式是否不使用逻辑运算符 int x=101; if(90<=x<=100) cout<<'A'; intx=101; 如果(90因为运算符具有相同的优先级,表达式从左到右求值: if( (90 <= x) <= 100 ) if( (90 <= 101) <= 100 ) // substitute x's value if( true <= 100 ) // eval

如果需要组合布尔表达式,我们通常使用逻辑运算符。我想知道表达式是否不使用逻辑运算符

int x=101;
if(90<=x<=100)
  cout<<'A';  
intx=101;

如果(90因为运算符具有相同的优先级,表达式从左到右求值:

if( (90 <= x) <= 100 )

if( (90 <= 101) <= 100 ) // substitute x's value

if( true <= 100 ) // evaluate the first <= operator

if( 1 <= 100 ) // implicit integer promotion for true to int

if( true ) // evaluate the second <= operator

if((90此表达式大致等于

int x=101;
bool b1 = 90 <= x; // true
bool b2 = int(b1) <= 100; // 1 <= 100 // true
if(b2)
    cout<<'A';
intx=101;

bool b1=90这是一个常见的错误源,因为它看起来是正确的,而且在系统上是正确的

int x=101;
if(90<=x<=100)

有点技术性的澄清:优先级和分组是独立的概念。大多数二进制运算符从左到右分组,这就是为什么
x
表示
(x
,如本例所示。赋值运算符从右到左分组,因此
A=b=c
表示
A=(b=c)
。在语言定义中,运算符的定义包括其分组行为的规范。+1是正确的答案。@PeteBecker我必须承认,这是我第一次听到“分组”。您能提供一个参考(如果可能,不是标准本身,也就是人类可读的东西)吗?@user463035818--抱歉,这都是标准。人们通常谈论优先级和关联性,但标准中没有定义这两个术语。优先级从语法中定义运算符的方式中脱落。关联性可能等同于分组,但我没有研究过。
int x=101;
if(90<=x<=100)
if (  (90 <= x) <= 100) 
if ( true <= 100 )
if ( true )