# 为什么会出现错误“表达式不可接受”？

``````(a > b) ? c = 10 : (a < b) ? c = 20 : c = 30;
``````

• dquis 回复

Because ternary operator `?:` has precedence over `=`, the expression is parsed as:

``````((a > b) ? c = 10 : (a < b) ? c = 20 : c) = 30;
``````

Because you can't "assign" to `(a > b) ? c = 10 : (a < b) ? c = 20 : c`, your compiler errors. You want:

``````(a > b) ? c = 10 : (a < b) ? c = 20 : (c = 30);
``````

但是写起来真的更好：

``````c = (a > b) ? 10 : (a < b) ? 20 : 30;
``````