"lvalue required as left operand of assignment" error in C

Hey all. I've been working on some fun with C and decided to write a Rock Paper Scissors game. The problem is, that when I try to compile the file, it gives "lvalue required as left operand of assignment" error. The error line is here:

for ((point1=0 && point2=0); ((point1=3) || (point2=3)); randStart++) {

point1, point2 and randStart are integer values by the way.

I use gcc and vim (which I doubt will help) and can give you all the code, if necessary.

Assuming you are wanting to initialise the variables to zero, and loop until one is equal to three:

for( point1 = 0, point2 = 0; point1 == 3 ||  point2 == 3; randStart++) {
1 Like

How are point1, point2 and randStart declared?

Also, as agma points out, it looks like you are confusing assignment and comparison:

// '=' assigns x the value 3
x = 3;

// '==' tests if x has the value 3
if (x == 3)
    /* ... */
1 Like

A little explanation of an "lvalue" might be in order.

An "lvalue" is something that can have the result of any computation assigned to it - it's pretty much some location in memory where you can put values. The statement "int abc;" declares and integer variable "abc", which can be an lvalue. The address of abc - "&abc" - is not an lvalue, because you can't assign a result to that - the address of the variable is the address. You can assign something to where that address points to by using the "" operator, so "( &abc )" is actually an lvalue. The integer constant "3" is not an lvalue.

The concept of an lvalue is pretty simple once you realize what it means.

Thanks all. It seems I was misusing && instead of comma. I also appreciate the info about lvalue. Thank you again.