3

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

user2991251
  • 33
  • 1
  • 1
  • 5

2 Answers2

4

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:

What are rvalues, lvalues, xvalues, glvalues, and prvalues?

Hope I shed some light on the problem!

Community
  • 1
  • 1
asalic
  • 949
  • 4
  • 10
0

"<<" 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;

Dushyant Gupta
  • 507
  • 1
  • 5
  • 24