左值要求作为分配的C左操作数 [英] lvalue required as left operand of assignment c
本文介绍了左值要求作为分配的C左操作数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在这个code
(nr % 10) % 2 == 0 ? a[i] = nr % 10 + 1 : a[i] = nr % 10;
我收到了左值要求作为分配的左操作数
。谁能帮我这个?
推荐答案
把括号围绕你的最后分配来解决这个:
Put parentheses around your last assignment to solve this:
(nr % 10) % 2 == 0 ? a[i] = nr % 10 + 1 : (a[i] = nr % 10);
这是因为分配具有较低的precedence比三元运算符等等code像 A = B? ð:C
被解析为 A =(B C:D)
,而不是(A = B)? C:D时
。 之间的分配
和:
并不需要放在括号内,因为没有任何语法歧义。
This is because assignment has a lower precedence than the ternary operator so code like a = b ? d : c
is parsed as a = (b ? c : d)
and not as (a = b) ? c : d
. The assignment between ?
and :
doesn't need to be placed in parentheses as there isn't any syntactic ambiguity.
这篇关于左值要求作为分配的C左操作数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文