L-Value in Expression : L-value require Error [Solved]



What is LValue ?

  1. Lvalue stands for left value and Expressions that refer to memory locations are called “l-value” expressions.
  2. In any Assignment statement L-Value must be a container ( i.e. which have ability to hold the data)
  3. Variable is the only container in C thus L Value must be any Variable.
  4. L Value Cannot be Constant,Function or any of the available data type in C

Diagram Showing Lvalue :

Example of LValue :

#include<stdio.h>
int main()
{
int num;
num = 5;
return(0);
}

In the above expression, Constant value 5 is being assigned to a variable ‘num’. Variable ‘num’ is called as storage region’s , ‘num’ can considered as LValue of an expression.

Important Concepts about : LValue of an Expression

Tip 1 : Lvalue cannot be a Constant

int main()
{
int num;
5 = num;  //Error
return(0);
}

Tip 2 : Lvalue cannot be a Constant Variable

int main()
{
const num;
num = 20;  //Error
return(0);
}

Tip 3 : Lvalue cannot be a MACRO

#define MAX 20
int main()
{
MAX = 20;  //Error
return(0);
}

Tip 4 : Lvalue cannot be a Enum Constant

enum {JAN,FEB,MARCH};
int main()
{
JAN = 20;  //Error
return(0);
}

Tip 5 : Lvalue cannot be a Data Type

#define<stdio.h>
#define max 125
struct book{
  char *name;
  int  pages;
};
void main()
{
book = {"C Programming",100};
}

How to solve this error : L-Value Require error ?

Causes of Error :

  1. Whenever we are trying to assign value to constant value
  2. Whenever we are trying to increment or decrement Constant Expression
  3. Inside if statement , if we try to write comparison operator as “= =” instead of ”==”, then we will get this error.

Solution :

Solution to this problem is very simple -

Always try to assign constant value to “Variable“. If you are using comparison operator then we don’t provide space in between operators.
In the next chapter we will be learning RValue of an expression which is also called as right value of an expression.