首先,最近我遇到了这个问题,但一直没有找到一个好的解释:
int x = (30 > 15)?(14 > 4) ? 1 : 0 : 2;
我之前使用过三元表达式,所以对它们很熟悉。老实说,我甚至不知道该如何称呼这个表达式......我认为它可以这样分解:
if (con1) or (con2) return 1 // if one is correct
if (!con1) and (!con2) return 0 // if none are correct
if (con1) not (con2) return 2 // if one but not the other
就像我说的一样,我并不是很确定,所以我的猜测可能相差甚远。