我说第一个是唯一的答案。 - int main(void){int putchar(int ),i = 0;无符号长t = 500555079,n [] = {t ,159418370,88921539,286883974,80500161,0};而(n [i])putchar(*(! (t& 1 )+!(t ||!++ i)+"#\ n")),(t&& 1+(t>> = i-) 〜-i))||(t = n [i] ^ n [i-1]);返回0;} 这在每个符合标准的编译器上都是正确的。 我猜逻辑是0和1的值,& ;&安培;类似于 乘法和||类似于(饱和)加法,这是 反映在它们的相对优先级中。 (可能另一个有用的类比是min / max但是C没有'' t $ / $ 有那些运营商..) &&运算符的优先级高于||。因此,&&首先评估b。这使得&& b || c 评估为(a&& b)|| c 请注意:与大多数其他运营商的情况不同,这些操作数 按顺序,从左到右,以及何时进行评估结果可以是 从已经评估的操作数确定, 其他人不会。例如, a * b - c 评估的顺序可以是:首先是c,然后是b,然后是a,然后是 乘法,然后减法。另一个可能是:第一个b,然后是a, 然后是乘法,然后是c,然后是减法。您知道订单的唯一事情是,显然,操作数必须在操作执行之前进行评估。乘法 将在减法之前发生。然而,在 a&& b || c / / 订单_must_是: 评估一个 如果a,那么 评价b 合乎逻辑且 其他 合理的结果,保证为0 b是未评估 如果结果为0 评估c 合乎逻辑或 其他 逻辑或保证导致1 c未评估 情况也是如此,而a || b&& c具有||的_value_ (b && c),操作数仍按从左到右的顺序进行评估;也就是说,如果a非零,那么,整个表达式都是真的,并且b和 c都不需要或将被评估。 这是一个很有用的功能,因为你可以做一些事情,比如 if(ptr!= NULL&& * ptr< MAX_VALUE) 而不用担心* ptr可能会在您检查之前进行评估 ptr不为空。 Richard a && b || cis evaluated as(a && b) || cor it is evaluated asa && (b || c)The theory and logic says it''s (a && b) || cDoes it depends on compilar also ?I don''t think so.In my view the 1st is the ultimate answer.What you people say ?Ajay 解决方案I say the first is the only answer.--int main(void){int putchar(int),i=0;unsigned long t=500555079,n[]={t,159418370,88921539,286883974,80500161,0};while(n[i])putchar(*(!(t&1)+!(t||!++i)+"# \n")),(t&&1+(t>>=i-~-i))||(t=n[i]^n[i-1]);return 0;}This is correct on every conforming compiler.I guess the logic is that with values 0 and 1, && is similar tomultiplication and || similar to (saturated) addition and this isreflected in their relative precedence.(possibly another useful analogy would be min/max but C doesn''thave operators for those..) The && operator has a higher precedence than ||. Therefore, a && b is evaluated first. That makes that a && b || c is evaluated as (a && b) || cAnd note: unlike what is true for most other operators, these operandsare evaluated in order, left to right, and when the outcome can bedetermined from the operands that have already been evaluated, theothers won''t be. For example, ina*b - cthe order of evaluation could be: first c, then b, then a, then themultiplication, then the subtraction. Another could be: first b, then a,then the multiplication, then c, then the subtraction. The only thingsyou know about the order is that, obviously, the operands must beevaluated before their operations are performed; and the multiplicationwill happen before the subtraction. However, ina && b || cthe order _must_ be:evaluate aif a, thenevaluate bdo logical andelseresult of logical and is guaranteed to be 0b is not evaluatedif result of and is 0evaluate cdo logical orelselogical or is guaranteed to result in 1c is not evaluatedIt is also the case that, while a || b && c has the _value_ of a || (b&& c), the operands are still evaluated in left-to-right order; that is,if a is non-zero, the whole of the expression is true, and neither b norc need or will be evaluated.This is a useful feature, because you can do things likeif (ptr!=NULL && *ptr<MAX_VALUE)without worrying that *ptr might be evaluated before you''ve checked thatptr is not null.Richard 这篇关于基本问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!