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

2
  • 3
    Did you mean newArr = (newArr << i) ^ 1 ? If you clarify what you want, you will probably solve your own problem.
    – CB Bailey
    Commented Nov 14, 2013 at 8:58
  • Answer that so I can checkmark it :) Commented Nov 14, 2013 at 8:59

2 Answers 2

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!

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;

1
  • 1
    You do not need to assign it. You can write a+b.
    – leemes
    Commented Nov 14, 2013 at 9:27

Not the answer you're looking for? Browse other questions tagged or ask your own question.