Yet Another Conditional Operator Nesting Question

前端 未结 2 1194
[愿得一人]
[愿得一人] 2021-01-05 16:48

As per C precedence tables, the ternary conditional operator has right-to-left associativity.

So, is it directly convertible to the equivalent if-else ladder?

2条回答
  •  误落风尘
    2021-01-05 17:32

    Your assumption is correct; however, it is often wise to add in parentheses for readability, e.g.:

    x ? ( y ? z : u ) : v
    

提交回复
热议问题