• Register
Welcome to Kodlogs, programming questions and answer website.
0 votes
5 views
What is lvalue required as left operand of assignment in C ? What is L value required?

I get following error (error: lvalue required as left operand of assignment) :

void loop(){

 Serial.println("Test?");

 Serial.println("{1}area");

 [u][b]if (Serial.available() = 1){

[/b][/u]    serialData = Serial.read;

   switch(serialData){

     case 1: action1(); break;

     default: error(1); break;

   }

 }

}
by (1.4k points)  
reshown by

1 Answer

0 votes

look on Ivalue and Rvalue basically whenever we use an equal to operator for assigning a value in a constant or in a variable at that particular time we should take care how these  Ivalue means the value on the left hand side and this R value means the value on the right hand side is going on so basically for a successful assignment we should put the variable on the left hand side so as you can see here a is equal to 20 so this is the  I value and this one is the R value so in the  I value means on the left hand side we only have a variable while on the right hand side we can have a constant we can have a variable we can have an expression which is evaluating a value so ultimately the value will come on the left hand side so make sure it is a variable but if you are defining a constant at that particular time you can have the name of a constant on the left hand side but that is the only exception after the constant is defined even if the next next line you cannot place the constant identifier on the left hand side of the assignment as here you can see 10 and 20 both are constant figures so you cannot place the constant on the left hand side it will give you an error that is  I value required so as I said in the  I value means the left hand side will be an variable only so let's see practically how we should go for such assignment tasks so now as you can see here I have defined three variables like int a B and C so if I want to initialize them with a value on the left hand side as you can see I have placed a variable and along with the value on the right hand side so this one is a constant while this one is a variable again if I want the similar thing I can do that also again on the left hand side I have B which is while on the right hand side I have a constant figure but if I try to do something in Reverse like 200 is equal to B then this will be an invalid operation so as soon as I will compile this it will show me the error in this particular line that that is  I value required means on the left hand side I cannot place the constant rather it should be a variable similarly if I will say C is equal to a plus B again this is a valid operation because on the right hand side I can pass an expression I can pass any variable I can pass a constant value but on the left hand side it must be a variable which will take the value because if I'll talk about equals to it will assign the value from right-hand side to left hand side so even this one is a valid operation so if I'll try to print the value of C I will get the value of the total of a and B that is 101 plus 200 that is 301 so let's check it out and as soon as I execute this we will see three zero one as the output but now if I'll try to do something in Reverse like suppose a plus B is equal to C again that is going to be an invalid operation because it will see a l value required because on the right left hand side I cannot have any expression so as now we know . 

by (9.7k points)  
...