错误:左值需要作为赋值的左操作数 (C)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19973320/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
error: lvalue required as left operand of assignment (C)
提问by user2991251
I see many different answers to this question and have looked at many of them yet I cannot find the answer to my problem.
对于这个问题,我看到了许多不同的答案,并且查看了其中的许多答案,但我找不到我的问题的答案。
The error im getting is
我得到的错误是
bitarray.c:27:19: error: lvalue required as left operand of assignment
(newArr << i) ^= 1;
Any ideas? Thanks
有任何想法吗?谢谢
采纳答案by asalic
You are trying to assign to a result from an operation another result. Try the following right way to do it:
您正在尝试将另一个结果分配给操作的结果。尝试以下正确的方法来做到这一点:
newArr = (newArr << i) ^ 1;
The idea is that you have to have a valid lvvalue and the temporary result of the "<<" is not a valid one. You need a variable like newArr. The following answer on SO explains many terms related to this situation:
这个想法是你必须有一个有效的 lvvalue 并且“<<”的临时结果不是一个有效的结果。你需要一个像 newArr 这样的变量。SO的以下答案解释了与这种情况相关的许多术语:
What are rvalues, lvalues, xvalues, glvalues, and prvalues?
什么是右值、左值、xvalues、glvalues 和 prvalues?
Hope I shed some light on the problem!
希望我对这个问题有所了解!
回答by Dushyant Gupta
"<<" is a binary operator just like "+" or a "-". It needs to be assigned to a variable. For Eg. you cannot just write this a+b; Correct way is c = a+b;
“<<”是一个二元运算符,就像“+”或“-”一样。它需要分配给一个变量。对于例如。你不能只写这个 a+b;正确的方法是 c = a+b;