First, Let me define how I understand operator associativity: Associativity dictates what operation goes first when two operands have the same precedence. If my understanding of associativity is correct, then can someone explain the following:
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
?