Right Associativity of Ternary Operator
问题 std::cout << (true ? "high pass" : false ? "fail" : "pass") is the same as std::cout << (true ? "high pass" : (false ? "fail" : "pass")) Since the ternary operator is right associative, why don't we perform the right-hand operation first? Shouldn't pass be printed instead of high pass ? 回答1: You misunderstood operator associativity. It's simply the way to group operators with the same precedence and doesn't affect order of evaluation in any way. So cond1 ? 1 : cond2 ? 2 : cond3 ? 3 : 4 will